Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!brl-adm!brl-smoke!smoke!rbj@icst-cmr From: rbj@icst-cmr (root) Newsgroups: net.lang.c Subject: Re: mixing scanf and gets Message-ID: <2566@brl-smoke.ARPA> Date: Fri, 11-Apr-86 11:36:54 EST Article-I.D.: brl-smok.2566 Posted: Fri Apr 11 11:36:54 1986 Date-Received: Wed, 16-Apr-86 03:28:24 EST Sender: news@brl-smoke.ARPA Lines: 26 > In article <2476@brl-smoke.ARPA> rbj@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