what am i doing wrong?

Jan 6, 2015 at 8:50pm
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 Jan 6, 2015 at 9:02pm
Jan 6, 2015 at 8:55pm
 
struct x c


needs a semi colon after c
Jan 6, 2015 at 8:57pm
still get the same error
Jan 6, 2015 at 9:03pm
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?

Jan 6, 2015 at 9:07pm
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 Jan 6, 2015 at 9:12pm
Topic archived. No new replies allowed.