Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

lvalue required

Name: Anonymous 2012-09-02 1:19

So, I've been trying to learn C out of the book "The C Programming Language", and in chapter 1 it gives me a program to count words, but every time I try 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;
        if (state == OUT){
            state = IN;
            ++nw;
        }
    }
    printf("%d %d %d\n", nl, nw, nc);
}

I try to compile it and it gives me the error "lvalue required as left operand of assignment" on line 15. I've looked it up on google and I couldn't find anything wrong with this. And from just looking at it, it looks fine.

What's going on here?

Name: Anonymous 2012-09-02 1:58

>>7
Oh, I didn't notice the '=' mistake. But look carefully at the change I made. In his version state will immediately assigned IN every time it's assigned OUT.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List