|
-
July 20th, 2007, 01:33 AM
#1
what is the problem about this code
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]);
}
-
July 20th, 2007, 01:49 AM
#2
Re: what is the problem about this code
 Originally Posted by lwong
scanf("%d\n",&c[i]);
why \n with scanf , remove it .
-
July 20th, 2007, 02:03 AM
#3
Re: what is the problem about this code
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...
}
Last edited by Krishnaa; July 20th, 2007 at 02:35 AM.
Regards,
Ramkrishna Pawar
-
July 20th, 2007, 02:23 AM
#4
Re: what is the problem about this code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|