gets fgets use
03-May-94 02:33:30
Sb: #40834-gets fgets use
Fm: John Draper 76703,4322
To: Henry Williams 73527,1446
Not sure how to get around the problem with scanf(), except to say "Don't use
it." One way to ensure that all characters are emptied from the buffer before
asking for characters is to just use a loop, like…
while(gets(buf));
gets(buf);
The while() will empty the buffer, and the second line will do the gets().
There is no way to prevent a crash if you use gets() and type beyond the buffer
length. You should either use fgets(), which specifies a length, or write your
own gets(), using getchar().
-larry