Date: Tue, 31 Mar 2009 07:50:22 -0400 From: William Gordon Rutherdale <will.rutherdale@utoronto.ca> To: FreeBSD Mailing List <freebsd-questions@FreeBSD.ORG> Subject: Re: Why?? (prog question) Message-ID: <49D2037E.7090108@utoronto.ca> In-Reply-To: <20090331025726.GA10888@thought.org> References: <20090331025726.GA10888@thought.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This isn't a BSD question. It's just about elementary C. As other
people pointed out, you could have easily caught it anyway just by
turning on warnings.
-Will
Gary Kline wrote:
> people, i've been under the weather for days and will probably be for a few more.
> new and TEMPORARY meds dont like me, ugh.
>
> can anybody clue me in why the followin joinline program fails to catch if argc == 1?
>
>
> /*
> * simple prog to join all | very nearly all lines of a text file that
> * make up one paragraph into one LONG line.
> *
> * paragraphs are delimiated by a single \n break.
> */
>
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
>
> main(int argc, char argv[])
> {
> char buf[65536];
>
> if (argc == 1)
> {
> printf("Usage: %s < file > newfile\n", argv[0]);
> exit (-1);
> }
> while (fgets(buf, sizeof buf, stdin) )
> {
> if (*buf == '\n')
> {
> fprintf(stdout, "\n\n");
> }
> else
> {
> buf[strlen(buf)-1] = ' ';
> fputs(buf, stdout);
> }
> }
> }
>
>
>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49D2037E.7090108>
