Originally Posted by
petedee
So that will do the opisite of what i want and only return the enter key?
If i crate an extra character which job would be just to store the enter key can i remove it from the string?
No, it means that the while loop will process ANY key that you press up until you press the enter key, which will then exit the loop. The '\n' character will not enter the loop, so you don't need to worry about it at all.
/*** EDIT ***/
*Grumbles* I should be more careful when I'm reading codes...
the precise line that you gave me,
Code:
while ((let2bg = getchar()) != '\n'); <-- didn't see this semicolon just now...
has the effect of clearing out the input stream.
that is to say in this example
Code:
int main (void)
{
char temp;
int data = 0;
while(data != 13)
{
printf("Please enter 12abc here: "); //gets user to type 12abc and press enter
scanf("%d", &data);
printf("enter 13 instead of 12abc to exit program.\n");
while((temp= getchar()) != '\n'); // comment and uncomment this line to see what happens
}
printf("bye bye\n");
system("PAUSE");
return 0;
}
if you comment out the line "while((temp= getchar()) != '\n');", the program will enter an infinite loop after you enter "12abc" because of the stuff that scanf is leaving in the input stream.