Dear,
Why the below code ask me to enter 6 numbers? does it not input c[0]....c[4]?
Code:int c[5], *y,i;
for(i=0;i<5;i++)
{
printf("%d:",i);
scanf("%d\n",&c[i]);
}
Printable View
Dear,
Why the below code ask me to enter 6 numbers? does it not input c[0]....c[4]?
Code:int c[5], *y,i;
for(i=0;i<5;i++)
{
printf("%d:",i);
scanf("%d\n",&c[i]);
}
why \n with scanf , remove it .Quote:
Originally Posted by lwong
Thats because you screwd it up by supplying \n in the format string, scanf does not shift the cursor to new line, it instead considers it as an input.
You should mention \n in 'print' kind of functions only.
Code:int c[5], *y,i;
for(i=0;i<5;i++)
{
printf("%d:",i); // You can supply \n here i.e. printf("%d:\n",i);
scanf("%d",&c[i]);
printf("\n"); // here print the new line...
}
oh, yes, thank you all.