what am i doing wrong?

getting "expected unqualified id before ' ' token"
1
2
3
4
5
6
7
8
9
10
11
12
13
  #include<stdio.h>
struct x{
	int a,b,c;
};
int main(){
	struct x a;
	struct x b;
	struct x c;
	x.b=1;
	x.c=2;
	printf("%d %d %d",x.a,x.b,x.c);
	return 0;
}
Last edited on
 
struct x c


needs a semi colon after c
still get the same error
Lines 9-10: x is a type name, not an instance of your struct. Where exactly do you think the 1 and 2 are being stored?

Line 11: Again x is a type name, not an instance of your struct. Which struct do you think you're printing? Lne 6, 7, or 8?

1
2
3
4
5
6
7
8
9
10
11
12

struct xeh{
	int a,b,c;
}e,f,g;
int main(){
	e.a = 0;
	f.b = 1;
	g.c = 2;
	printf("%d %d %d",e.a,f.b,g.c);
	return 0;
}


got it working.

As abstractAnon says.. I was hunting for the solution for a minute because I'm brand new to this so I went here:

http://www.cplusplus.com/doc/tutorial/structures/

if you scroll down you can see the layout in the first particular program.

You:

A) created the struct x
B) gave it variables a,b,c of type int
C) created objects of x but did not name them properly
D) set the objects to values but it didn't work because the objects were named the same as the variables


NOw abstractionanon maybe you can help me with my own probnlem? hehehe
Last edited on
Topic archived. No new replies allowed.