PDA

View Full Version : whats wrong with my code?!



psiko_scweek
May 23rd, 2006, 07:44
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...

yaustar
May 23rd, 2006, 10:06
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.

psiko_scweek
May 23rd, 2006, 12:54
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.

yaustar
May 23rd, 2006, 13:27
What is the EXACT error? It works on my compiler.

psiko_scweek
May 23rd, 2006, 13:42
huh!?

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

im using Cygwin and the PSPSDK if that helps any.

yaustar
May 23rd, 2006, 16:13
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.