Possible Duplicate:
Using fflush(stdin)
My code is:
scanf("%d", &_choice);
fflush(stdin);
gets(input);
I use fflush(stdin);
to remove the '\n'
character that was left after scanf
.
However, I found out that it doesn't work, and gets
automatically takes the '\n'
char and continues.
I solved it by using getchar()
instead of fflush
but I still can't figure out why didn't fflush
work...
Edit: I understand now fflush
is for output streams only.
But is there a command for "cleaning" stdin
from junk?