From owner-freebsd-questions@FreeBSD.ORG Tue Mar 31 12:00:06 2009 Return-Path: Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ED2D8106564A for ; Tue, 31 Mar 2009 12:00:06 +0000 (UTC) (envelope-from will.rutherdale@utoronto.ca) Received: from mail.vex.net (smaug.vex.net [208.76.104.132]) by mx1.freebsd.org (Postfix) with ESMTP id BF5168FC0A for ; Tue, 31 Mar 2009 12:00:06 +0000 (UTC) (envelope-from will.rutherdale@utoronto.ca) Received: from [192.168.110.8] (unknown [207.35.13.75]) by mail.vex.net (Postfix) with ESMTPA id 790C21701C for ; Tue, 31 Mar 2009 07:50:23 -0400 (EDT) Message-ID: <49D2037E.7090108@utoronto.ca> Date: Tue, 31 Mar 2009 07:50:22 -0400 From: William Gordon Rutherdale User-Agent: Thunderbird 1.5.0.14ubu (X11/20080505) MIME-Version: 1.0 To: FreeBSD Mailing List References: <20090331025726.GA10888@thought.org> In-Reply-To: <20090331025726.GA10888@thought.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Re: Why?? (prog question) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Mar 2009 12:00:07 -0000 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 > #include > #include > > 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); > } > } > } > > >