Mail Archives: djgpp/1998/05/24/01:31:36
Peleg79593 wrote in message
<1998052404332600 DOT AAA20938 AT ladder03 DOT news DOT aol DOT com>...
:Okay, so I want to use
:
:gets(x);
========
No, you don't.
Use fgets(x, sizeof x, stdin); /* for staticly allocated x */
or with the size_t argument otherwise specified.
========
:
:instead of scanf in a bunch of input functions. So I replace all the scanfs.
:But, then, the program just skips past the gets(x) without accepting any
input
:as though there were something still in the buffer. So I add fflush(stdin)
========
Don't invoke undefined behavior. fflush is defined for output streams,
not input files, even in GCC.
========
:before and after all of my buffered inputs. Same problem. So, then, I put:
:
:gets(trash);
:
:before every
:
:gets(x);
:
:and, voila, it works. What gives here? Am I doing something wrong, or is
this
:an acceptable way to clear the buffer?
======
Post the real code. Your description makes it sound like
you have misdiagnosed the problem.
======
:
:
:
- Raw text -