Just starting to learn C - trying to figure out what this means exactly - "When scanf encouters a character that can't be part of the current item (in this case an array), the character is Put Back to be read again during the scanning of the next input item or during the next call of scanf. "
I wrote this program to see what would happen if i entered too many numbers on the same line before hitting the enter key. I then did two more scanf() functions and print() and the data that was "put back" because i entered 12 integers instead of only 10 automatically is printed out. I'm just trying to understand how scanf works with the "buffer" that it goes to. Any insight into how this works would be great. I've read that leaving a space before the conversion specifier (%d here) is necessary because if you don't the "newline" character will be read by scanf the next time it's called.
/***********************************************/
Code:
#include<stdio.h>
main()
{
int a, b, c, d[10];
printf( "Please enter 10 numbers: \n" );
for ( b = 0; b < 10; b++)
{
scanf( " %d", &d[b] );
}
printf( "Here are the numbers you entered: \n\n" );
for ( b = 0; b < 10; b++)
printf( "%d ", d[b] );
printf( "\n\nPlease enter another number: " );
scanf( " %d", &a );
printf( "\n\n %d \n\n", a );
printf( "\n\nPlease enter another number: " );
scanf( " %d", &c );
printf( "\n\n %d \n\n", c );
return 0;
}