fflush(stdin) function does not work

The fflush function does not flush data out of an input stream; it is instead used to push data buffered in an output stream to the destination. This is documented here. As seen in this earlier SO question, trying to use fflush(stdin) leads to undefined behavior, so it’s best to avoid it.

If you want to eat the newline from the return character entered when the user finished typing in their character, instead consider the following:

scanf("%c%*c", &sect_cat);

This will eat the newline rather than leaving it in stdin.

Hope this helps!

Leave a Comment