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 2:38


#include <stdio.h>
main(){ int c, nl, nw, nc; bool out; out = false;
  nl = nw = nc = 0;
  while ((c = getchar()) != EOF){
    ++nc;
    if (c == '\n') ++nl;
    if (c == ' ' || c == '\n' || c == '\t') out = true;
    if (out){ out = false; ++nw; }}
  printf("%d %d %d\n", nl, nw, nc);}

Fucking optimized for space and corrected for proper function.
K&R is pig disgusting.

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