obvious code does not compile
Hi everybody,
this is my first post here...I choose Kernighan , Ritchie Book to follow and refresh my knowledge in C and this site forum to accompany this process...
I am using Microsoft Visual C++ 2008 to run the codes.
the following code is basically an example from K,R Book and is for counting words and characters in a text.It does not compile and I spent a whole day but didnt figure out whats wrong
Code:
#include <stdio.h>
#define in 1;
#define out 0;
void main(void){
int c=0;
int w=0;
short int state=out;
char ch;
ch=getchar();
while((ch=getchar())!='\n'){
c++;
if(ch==' ' || ch=='\t')
state=out;
else if(state==out){ //Line 16 which is source of all errors.
state==in;
w++;
}
}
printf("Totally %d words containing %d characters.",w,c);
}
it displays following errors which as I check the syntax, its allready correct but again raise errors which I cant stand anymore !
main.cpp(16) : error C2181: illegal else without matching if
main.cpp(16) : error C2143: syntax error : missing ')' before ';'
main.cpp(16) : error C2059: syntax error : ')'
can anyone help whats the problem with this compiler ? Its the first examples of the book and too disappointing if it want to continue like this..