1

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?

Community
  • 1
  • 1
cookya
  • 3,019
  • 7
  • 26
  • 37

1 Answers1

4

Because fflush is for output streams.

And at any rate, fflush is not for "removing \n characters"...

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680