开发者

C: Code below cannot be Compiled?

开发者 https://www.devze.com 2023-02-02 03:34 出处:网络
#include <stdio.h> #define IN1/* inside a word */ #define OUT0/* outside a word */ /* count lines, words, and characters in input */
  #include <stdio.h> 

   #define IN   1  /* inside a word */ 
   #define OUT  0  /* outside a word */ 

   /* count lines, words, and characters in input */ 
   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); 
   } 

I got K&R book but there are some codes that don't compile !

it gives me - 19 C:\Users\Nom\Desktop\Untitled1.c invalid lvalue in assignment


edit: now it works, thanks guys, but now it do开发者_运维问答es nothing ! the printf statement doesn't work. It opens the dos console, I type anything and it just return a new line. I'm using Dev-C++ 4.9.9.2


edit: I put the printf statement inside the while loop and it works now. thanks


In if (c == ' ' || c == '\n' || c = '\t') the last = should probably be ==


       if (c == ' ' || c == '\n' || c = '\t') 

you're missing an = in the final or clause, should be

       if (c == ' ' || c == '\n' || c == '\t') 
                                       ^^ here
0

精彩评论

暂无评论...
验证码 换一张
取 消