Differences between scanf and getchar in C -
i trying explain friend c coding , asked me why code (with "scanf") didn't work.
#include
int main() { char x=scanf("%c",&x); printf("%c\n",x); return 0; }
and 1 yes
#include <stdio.h> int main() { int k; char x=getchar printf("%c\n",x); return 0; }
when scanf
completes, x
contains character read. however, value overwritten when x
assigned return value of scanf
, number of items matched or eof in event of error.
if call scanf
without assigning return value x
should expected result.
for example, should work.
char x; scanf("%c",&x);
Comments
Post a Comment