I'll cut it down to the bare basics, as the rest of the code is unnecessary. It's a basic text adventure program.
// defines numeric values for each room
typedef enum {
KITCHEN,
PANTRY,
HALLWAY_1,
HALLWAY_2,
TROLLS_DOMAIN,
EMPTY_ROOM_1,
EMPTY_ROOM_2,
EXIT,
NO_ROOM
} en_rooms;
// defines a struct type to store room data
typedef struct room{
char name[50];
char desc[50]; // description
} Room;
// fills the array r with info on each room.
void room_setup(Room *r){
strcpy(r[KITCHEN].name, "Kitchen");
strcpy(r[KITCHEN].desc, "This is the kitchen.");
}
int main(void){
...
Room rooms[10];
room_setup(rooms); // fill rooms array with info
en_rooms currentRoom = KITCHEN; // set the starting room to the kitchen
// main game loop
while(1){
...
// print room name + description
printf("-- %s --\n", rooms[currentRoom].name);
printf("%s\n", rooms[currentRoom].desc);
...
}
}
For whatever reason, the output is this:
-- rP@ --
This is the kitchen.
Can anyone help me work out why strcpy() will copy the rooms description, but not it's name properly?