Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   I'm getting parse errors (http://www.go4expert.com/forums/im-getting-parse-errors-t4815/)

imalumberjak 23Jun2007 08:44

I'm getting parse errors
 
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. :)

imalumberjak 23Jun2007 08:46

Re: I'm getting parse errors
 
that first sentence should say "keep in mind my", not "keep in my my". Is there a way to edit posts here?

DaWei 23Jun2007 08:56

Re: I'm getting parse errors
 
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 23Jun2007 09:11

Re: I'm getting parse errors
 
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 23Jun2007 09:44

Re: I'm getting parse errors
 
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.

DaWei 23Jun2007 09:47

Re: I'm getting parse errors
 
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.


All times are GMT +5.5. The time now is 21:26.