Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Feb 2005 21:51:25 -0800 (PST)
From:      Mark Jayson Alvarez <jay2xra@yahoo.com>
To:        Mark Jayson Alvarez <jay2xra@yahoo.com>, freebsd-questions@freebsd.org
Subject:   Re: Word counting by Kernighan won't compile =(
Message-ID:  <20050301055125.39445.qmail@web51604.mail.yahoo.com>
In-Reply-To: <20050301052323.29837.qmail@web51610.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--- Mark Jayson Alvarez <jay2xra@yahoo.com> wrote:
Hi, everyone!
No need to answer this one. I think I know what my
problem is. The book contains typographical errors
such that example programs might not work if one would
just copy and paste it. Particularly in the example
below, the second if's third condition lacks one "="
sign that's why the compiler complained an error of
assigning values when testing for equality is what it
really wants to do. 
> Hi,
>   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" 


> 
> It exited with errors:
> 
> word.c: In function `main':
> word.c:17: error: invalid lvalue in assignment
> 
> Any idea what this means?
> 
> Thanks.
> 
> 
> 
> Here's the code:
> #include<stdio.h>
> 
> #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);
> }
> 
> 
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> Yahoo! Mail - 250MB free storage. Do more. Manage
> less. 
> http://info.mail.yahoo.com/mail_250
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
>
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe@freebsd.org"
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050301055125.39445.qmail>