From owner-freebsd-questions@FreeBSD.ORG Wed Mar 2 01:12:14 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8967D16A4CE for ; Wed, 2 Mar 2005 01:12:14 +0000 (GMT) Received: from smtpq1.home.nl (smtpq1.home.nl [213.51.128.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3BAFE43D1D for ; Wed, 2 Mar 2005 01:12:14 +0000 (GMT) (envelope-from luyt@ovosoft.nl) Received: from [213.51.128.136] (port=55551 helo=smtp5.home.nl) by smtpq1.home.nl with esmtp (Exim 4.30) id 1D6IPN-0007TG-DP for freebsd-questions@freebsd.org; Wed, 02 Mar 2005 02:12:13 +0100 Received: from cc351901-a.groni1.gr.home.nl ([82.73.114.87]:34221 helo=localhost.invalid) by smtp5.home.nl with esmtp (Exim 4.30) id 1D6IPM-0003Jp-Ih for freebsd-questions@freebsd.org; Wed, 02 Mar 2005 02:12:12 +0100 From: Luyt To: freebsd-questions@freebsd.org Date: Wed, 2 Mar 2005 02:15:07 +0100 User-Agent: KMail/1.7.2 References: <20050301052323.29837.qmail@web51610.mail.yahoo.com> In-Reply-To: <20050301052323.29837.qmail@web51610.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200503020215.07877.luyt@ovosoft.nl> X-AtHome-MailScanner-Information: Neem contact op met support@home.nl voor meer informatie X-AtHome-MailScanner: Found to be clean Subject: Re: Word counting by Kernighan won't compile =( X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2005 01:12:14 -0000 On Tuesday 01 March 2005 06:23, Mark Jayson Alvarez wrote: > Sorry for asking this question here. I just thought > that this might be a platform specific issue=). I'm > reading this book(The C Programming Language 2nd > Edition by Brian W. Kernighan. Upon reading the book, > I came up with this example code. It says, it will > count the number of words, lines and characters in the > command line, until I send an EOF signal. I copied it > verbatim and tried compiling it with plain "cc > myprog.c" #include #define IN 1 #define OUT 0 main() { int c, nl, nw, nc, state; state = OUT; nl = nw = nc = 0; while ((c = getchar()) != EOF) { ++nc; if (c == '\n') ++nl; if (c == ' ' || c == '\n' || c == '\t') state = OUT; else if (state == OUT) { state = IN; ++nw; } } printf("%d %d %d\n", nl, nw, nc); } Compile & sample output: luyt@Deschutes /home/luyt % gcc wc.c -o wc luyt@Deschutes /home/luyt % ./wc