mixing scanf and gets
root
rbj at icst-cmr
Sat Apr 12 02:36:54 AEST 1986
> In article <2476 at brl-smoke.ARPA> rbj at icst-cmr (Root Boy Jim) writes:
> >Fgets is worthless on binary data. It returns its first argument, which I
> >already know. If a null is part of the data, how do you know where it
> >stopped reading? Well if you're lucky, there will be a newline in there
> >and that's the end of it. But if you're reading blocks of nulls, you're
> >SOL. I would like fgets to return the number of chars read.
>
> Clearly fgets isn't intended for binary data. (Who writes line-oriented
> binary data??) Probably fread is what you want. However, I think you're
> right that nchars is a more useful return value (though I'd be satisfied
> with a boolean).
>
> Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint
Allow me to clarify my position. I came across this while writing an
SMTP implementation. Most of what you see is text, altho ANY char
may be escaped with a backslash. It would have been easy enuf to look
for a '\n' that was not escaped and pass back the entire line.
Even with ascii data, I often find I want the count more often than I
want the first argument, which I already know. Perhaps it's designers
didn't know what to return, so they just punted & returned the first
argument because so many other stdio funxions did. This is
regrettable, because fgets has the char count right at hand.
(Root Boy) Jim Cottrell <rbj at cmr>
More information about the Comp.lang.c
mailing list