Silly question but I cannot find the answer online..
Is their a C function that does the same as cin.ignore() in C++?
Sombody said it was fflish( stdlin ) but iv heard thats bad...
any info appreicated
Silly question but I cannot find the answer online..
Is their a C function that does the same as cin.ignore() in C++?
Sombody said it was fflish( stdlin ) but iv heard thats bad...
any info appreicated
Double Helix STL
Considering that one can actually use cin.get() instead of cin.ignore() in C++ and just ignore what is returned, I would think that one can do the same in C, but with getchar() instead.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
If you want it to wait until the user hits enter I do:
Code:while(getchar() != '\n');
check for EOF.Code:while((getchar() != '\n') && !feof(stdin)) ; /* Empty loop */
I don't understand, what's bad about the pattern?
Suppose you've just read the last char in the file. You are at the end-of-file. You call feof() and it returns... false! feof() will not return true until a read operation has FAILED while at the end of file. Result? You pass through the loop one time too many.
As I said, in THIS case it doesn't matter, because the loop is empty. In general, controlling an input loop with feof() is not correct.
And there is a details description of why feof shouldn't be used as well in the FAQ. Have a go with the FAQ once.
ssharish2005
No there isn't. (at least not that I'm aware of)
Using getchar() will not work if there is nothing to clear in the buffer -- it will force you to press return an extra time.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.