I'm getting parse errors

imalumberjak's Avatar, Join Date: Jun 2007
Newbie Member
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.

Last edited by shabbir; 23Jun2007 at 09:36.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code
imalumberjak's Avatar, Join Date: Jun 2007
Newbie Member
that first sentence should say "keep in mind my", not "keep in my my". Is there a way to edit posts here?
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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.
imalumberjak's Avatar, Join Date: Jun 2007
Newbie Member
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'
}
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by imalumberjak
that first sentence should say "keep in mind my", not "keep in my my". Is there a way to edit posts here?
After you reach 50 posts.

Last edited by shabbir; 23Jun2007 at 09:47.. Reason: Typo of 10 instead of 50
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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.