hai.. I am new one to C. the following code makes infinite loop ...!! how it happen..
Thank you..Code:main() { int x; char y[10]; for(x=0;x<10;x++) x=scanf("%c",&y[x]); printf("%d",x); }
hai.. I am new one to C. the following code makes infinite loop ...!! how it happen..
Thank you..Code:main() { int x; char y[10]; for(x=0;x<10;x++) x=scanf("%c",&y[x]); printf("%d",x); }
What do you expect scanf() to return?
number of characters entered
It returns the number of successful assignments, so in your case, it always returns 1.
Last edited by root4; 08-11-2012 at 02:51 PM.
But in this case it return garbage value.....
Code:main() { int x,count; char y[10]; for(x=0;x<10;x++) count+=scanf("%c",&y[x]); printf("%d",count); }
Because count was never given an initial value.