Hello,
I was reading this amazing book by Dennis Ritchie (RIP) and some codes just don't compile. I can understand the logic of the program, but somehow, GCC don't accept it. For instance, for this code, GCC returns "cprog.c:17:3: error: lvalue required as left operand of assignment".
Code:
- #include<stdio.h>
- #define IN 1 /* inside a word */
- #define OUT 0 /* outside a word */
- /* count lines, words, and characters in input */
- int 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);
- }
p.s: Here in the forum, the code tags don't accept blank lines. In my code, the line number 17 is:
if(c == ' ' || c == '\n' || c = '\t')
Can someone plz give me a hand here?
Many tnx in advance!