1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

I'm getting parse errors

Discussion in 'C' started by imalumberjak, Jun 23, 2007.

  1. imalumberjak

    imalumberjak New Member

    Joined:
    Jun 23, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Jun 23, 2007
  2. imalumberjak

    imalumberjak New Member

    Joined:
    Jun 23, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    that first sentence should say "keep in mind my", not "keep in my my". Is there a way to edit posts here?
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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.
     
  4. imalumberjak

    imalumberjak New Member

    Joined:
    Jun 23, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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'
    }
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    After you reach 50 posts.
     
    Last edited: Jun 23, 2007
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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.
     

Share This Page