So a quick Google search for fflush(stdin) for clearing the input buffer reveals numerous websites warning against using it. And yet that’s exactly how my CS professor taught the class to do it.
How bad is using fflush(stdin)? Should I really abstain from using it, even though my professor is using it and it seems to work flawlessly?
Simple: this is undefined behavior, since
fflushis meant to be called on an output stream. This is an excerpt from the C standard:So it’s not a question of "how bad" this is.
fflush(stdin)is simply not portable, so you should not use it if you want your code to be portable between compilers.