mixing scanf and gets
KW Heuer
kwh at bentley.UUCP
Fri Apr 11 07:36:16 AEST 1986
In article <2476 at brl-smoke.ARPA> rbj at icst-cmr (Root Boy Jim) writes:
>The problem with sscanf is that if your input only partially matches,
>there is no way to tell where [the next input character is].
Agreed. I'm somewhat surprised this isn't listed under "BUGS". Of
course, in many applications you don't care (just output "syntax error"
and toss the line away); and it may be feasible to re-parse the entire
line with a new format in any case.
>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
More information about the Comp.lang.c
mailing list