Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Some ideas about c? Date: Fri, 19 May 2017 11:59:24 -0700 Organization: None to speak of Lines: 49 Message-ID: References: <87bmqp7utb.fsf@gmail.com> <48eb1c1f-c162-45ff-b7ce-74108ee6c522@googlegroups.com> <87h90gix34.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="189d31b8aa2df37c9a5da9ba095e96a2"; logging-data="18620"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Z+DBiBWaTJSxHA5+5Knu5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:QohTmxT1vgNl76ZgueNUPYc5z34= sha1:lGQnr/DsU0OHFGT3RoF8Rp2qkqQ= Xref: csiph.com comp.lang.c:110407 Ben Bacarisse writes: > Keith Thompson writes: >> supercat@casperkitty.com writes: >>> On Friday, May 19, 2017 at 7:38:13 AM UTC-5, Scott Lurndal wrote: >>>> Gareth Owen writes: >>>> >scott writes: >>>> > >>>> >> int main() { char buffer[512]; fputs(fgets(buffer, sizeof(buffer), >>>> >> stdin), stdout); } >>>> > >>>> >Great. Except it doesn't work if the input line is too big. >>>> >>>> Sure it does. It just truncates it. And the programmer is, of >>>> course, aware of that. >>> >>> It doesn't truncate lines; it wraps them. Sometimes that's desirable, and >>> sometimes not. A function which behaved like fgets() but provided a choice >>> of behaviors (truncate, wrap, or trap/signal) would have been helpful, but >>> fgets is what it is. >> >> No, it doesn't wrap. >> >> The program reads and prints a single line, discarding any remaining >> input. If the line is longer than 512 characters, including the >> trailing newline, it prints only the first 512 characters and discards >> the rest. (Which means that the output might not contain a terminating >> newline even if the input does.) > > I found this description a bit confusing so I'll offer a clarification. > Instead of "and discards the rest" I'd say "and leaves the rest to be > read by later input calls". > > Discarded input sounds to me like input lost forever. Yes, the input is lost forever when the program (shown above in its entirety but missing `#include ` terminates. I suppose another program executed after this one could read the input, but that's outside the scope of C. I think people are assuming that the fputs(fgets(...)) line is meant to be part of some larger program. I'm not making that assumption, and the original problem description doesn't imply it. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"