In the following C code:
char name[20];
int a;
int b;
for(i=0;i<10;i++)
{
printf("\nEnter name, a & b: ");
scanf("%s %d %d",name,&a,&b);
}
does scanf read in the '\n' entered at the end of scanf() in 1st iteration, for the 2nd iteration inputs?
scanfleaves the input stream pointing to the\n. In your case it doesn’t make a difference: each time it’s called,scanfwill move along until it finds the next non-whitespace character. So giving it 10 lines ofname, a, bas input will work as you expect.But consider this:
fgetsreads until it finds the first newline character, sostrwill just get a value of\n, andfgetswill not read the next line of input.