Simple C code does not compile in VS2008.

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.It tells there is problem with else if syntax whichi is obviously correct but again there is errors.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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..
1.) Defines don't end with a ';'
2.) void main(void) is wrong, use int main(void)
3.) state == in i think you meant state = in
Last edited on
Thank you very much....I correct them just now and it works.I should be more accurate reading and typing codes.

BTW , I have used Eclipse editor before for java and it was just Great and helpful.It helps you with braces by highliting them , formats the code so you dont miss anything and so many other simple bur powerful features.You cant compare the producivity that Eclipse brings to you with MS VS.
MSVS highlights braces too; I think if you go to Tools -> Options, Fonts & Colors you can set what matching braces change to.
it does highlight them , but after that if you want to read your code or review it and you put your cursur beside a brace or paranthesis, it doesnt show you which is the matching brace or paranthesis and does not highlight anymore.
Eclipse do this and it helps a lot!
Topic archived. No new replies allowed.