This is a simple program, but keep in my my knowledge of C is also very simple. I'm getting parse errors in two areas in this program, and I'm not sure why: ----------------------------- Code: typedef enum { now=10, next, last } grade; typedef union { int age1; float age2; }age; main() { struct {char name[20]; int age;} info; grade now; strcpy(info.name, "my name, which I don't feel comfortable posting"); info.age=15; UNION age=info.age; //Parse error before 'union' (capitalized here so you can see it) printf("This program is by %s, age %d. He is currently is grade %d." INFO.name, age.age2, grade); //parse error before 'info' (capitalized here so you can see it) } ----------------------------- There are probably other problems in this programs as well, but Dev isn't pointing them out. Any help would be greatly appreciated.
that first sentence should say "keep in mind my", not "keep in my my". Is there a way to edit posts here?
There's a "Before you make a query" thread. Did you happen to read that before you made your query? If so, what didn't you understand about code tags? Typos are much easier to ignore than ugly code which has lost its indentation and formatting.
Sorry, I didn't see that thread. I'm still having trouble finding it, but here's a better looking version of the code: Code: typedef enum {now=10, next, last} grade; typedef union {int age1 ;float age2;} age; main() { struct {char name[20]; int age;} info; grade now; strcpy(info.name, "my name is here in the real code"); info.age=15; union age=info.age; // parse error before 'union' printf("This program is by %s, age %d. He is currently is grade %d." IFNO.name, age.age2, grade); // parse error before 'info' }
You're being sloppy with your choice of labels. For instance, the typedef makes "age" a type, equivalent to "union {int age1 ;float age2;}". then you write, "union age = ....". Would you write "union union {int age1 ;float age2;}" and expect to NOT get a parse error? Precisely what were you expecting to assign "info.age" to? Would you want to come back in a year's time and deal with lebenty-four variables with the same name, even if you managed to maintain correct syntax? Are you shooting for obfuscation or cuteness, or just not paying attention? Just curious.