Results 1 to 6 of 6

Thread: whats wrong with my code?!

                  
   
  1. #1
    DCEmu Regular psiko_scweek's Avatar
    Join Date
    Apr 2006
    Posts
    315
    Rep Power
    69

    Default whats wrong with my code?!

    ok here it is...


    typedef struct robot ROBOT;

    struct robot {
    char *name;
    int energy;
    };

    int main() {
    int i;

    ROBOT robots[3];

    robots[0].name = "Lunar Lee";
    robots[0].energy = 50;
    robots[1].name = "Planetary Pete";
    robots[1].energy = 20;
    robots[2].name = "Martian Matt";
    robots[2].energy = 30;
    }

    (for the most part)
    and it keeps giving me the error...
    "syntax error before "." token"

    i dont understand why...

  2. #2
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    Remove the word struct from the typedef so it becomes:

    typedef robot ROBOT

    If there are still errors put the typedef after the struct robot declaration.

    If you still get errors, print out the errors here.

    In general the typedef should be ideally be declared with the struct:

    typedef struct {
    int data;
    int text;
    } S1;

    Or even better if you are using C++, use classes.

  3. #3
    DCEmu Regular psiko_scweek's Avatar
    Join Date
    Apr 2006
    Posts
    315
    Rep Power
    69

    Default

    ok i think i tried that....

    typedef struct{
    int x, y;
    }Enemy;

    Enemy Robots[10];

    Robots[1].x = 100;

    and it still errors out...same error.

  4. #4
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    What is the EXACT error? It works on my compiler.

  5. #5
    DCEmu Regular psiko_scweek's Avatar
    Join Date
    Apr 2006
    Posts
    315
    Rep Power
    69

    Default

    huh!?

    main.c:58 error: syntax error before '.' token
    make *** [main.o] Error 1

    im using Cygwin and the PSPSDK if that helps any.

  6. #6
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    You need to show more/whole code, it works 100% fine here.

    Edit: There may be an error prior to that line causing a knock on effect. List you entire error output and source.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •