Page 1 of 1
delclaring and using struct
Posted: Wed Oct 28, 2015 9:00 pm
by matteus
Code: Select all
typedef struct {
char Name[24];
char Job[25];
char Specialism[18];
} Expert;
struct Expert Experts[6];
strcpy(Experts[0].Name, "David Barby");
strcpy(Experts[0].Job, "Expert Independent Valuer");
strcpy(Experts[0].Specialism, "Pottery");
I wanted to check I was doing this correctly? There seems to be several errors though
Re: delclaring and using struct
Posted: Wed Oct 28, 2015 9:45 pm
by Grind
You don't need to put "struct" in front of the type if you used a typedef:
Expert Experts[6]; // Would be fine
Everything else looks valid. Are you running into a problem with this? I think SGDK has a strcpy so that should work. Be careful though as C standard libraries use null terminated strings. You are actually writing a 26 byte array into Job[25]. Likely with your code an attempt to draw/print Experts[0].Job would print "Expert Independent ValuerPottery" due to the null char '\0' being overridden by the P, but I didn't test it myself.
Re: delclaring and using struct
Posted: Wed Oct 28, 2015 10:29 pm
by matteus
Cheers, I realised I'd not made the char lengths long enough
