In article <e2**********@canopus.cc.umanitoba.ca>,
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
Gaijinco wrote: as an example, where scanf() acts like gets()
As the scanf() form leaves the newline in the input stream, but
the gets() form does not, the two are not equivilent.
You could use:
scanf("%[^\n]\n",line);
but you should be sure you understand the result you would get
if end of file occurs before you encounter a \n .
Also, since \n is a whitespace directive for the fscanf family, it
will consume not only the newline (if it exists) but any following
whitespace. If this scanf is used in a loop, for example, it will
remove leading whitespace from all lines after the first. So again,
this is not equivalent to gets().
(It *is* similar to gets() in that, as presented, it can overflow
the line object. There should be a maximum size specifier on that
conversion directive.)
--
Michael Wojcik
mi************@microfocus.com
Even though there may be some misguided critics of what we're trying
to do, I think we're on the wrong path. -- Reagan