I have encountered an problem that doubt me a lot, the problem is what you see below:
I have write a little program as what you see below:
---------------------------------------------------------------
#include<stdio.h>
#define IN 1;
#define OUT 0;
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);
}
-------------------------------------------------------------------
then i received the message after I complied the program as what you see below:
-----------------------------------------------------------------------
D:\workspace\a>gcc sample_001.c
sample_001.c: In function `main':
sample_001.c:27: error: syntax error before ';' token
sample_001.c: At top level:
sample_001.c:33: error: syntax error before string constant
sample_001.c:33: error: conflicting types for 'printf'
sample_001.c:33: note: a parameter list with an ellipsis can't match an empty pa
rameter name list declaration
sample_001.c:33: error: conflicting types for 'printf'
sample_001.c:33: note: a parameter list with an ellipsis can't match an empty pa
rameter name list declaration
sample_001.c:33: warning: data definition has no type or storage class
D:\workspace\a>gcc sample_001.c
sample_001.c: In function `main':
sample_001.c:27: error: syntax error before ';' token
sample_001.c: At top level:
sample_001.c:32: error: syntax error before string constant
sample_001.c:32: error: conflicting types for 'printf'
sample_001.c:32: note: a parameter list with an ellipsis can't match an empty pa
rameter name list declaration
sample_001.c:32: error: conflicting types for 'printf'
sample_001.c:32: note: a parameter list with an ellipsis can't match an empty pa
rameter name list declaration
sample_001.c:32: warning: data definition has no type or storage class
-----------------------------------------------------------------------
but when I modified the else if sentence "else if (state==OUT) " to "else if (state==0) ", means I changed the OUT with an integer value '0'(zero) the program seems goes well.