I have my own data type since C89 doesn't allow bool type. I can't use C99 sadly.
I have tested the below code and my program is not even recognizing that the names are different. The names are working just fine. I have those loaded in an instance of the struct.
struct ROOM roomList [MAX_ROOMS_COUNT]; I used memset and strcpy to copy in a list of rooms from a room array. Testing this gives me the results I want like so...
printf("%s", roomList[1].name) printf("%s", roomList[2].name) ... printf("%s", roomList[7].name) The rooms array has 7 values.
#define MAX_ROOMS_COUNT 7 typedef enum { true = 1, false = 0 } boolean; struct ROOM { char name[8]; char* type; int numConnections; char* connections [MAX_CONNECTIONS_COUNT]; }; boolean isSameRoom(struct ROOM x, struct ROOM y) { //printf("Is Same Room, 1:%s, 2:%s\n", x.name, y.name); if (x.name == y.name) { //printf("ROOM IS SAME!"); return true; } else { return false; } } struct ROOM getRandomRoom() { int random = rand() % MAX_ROOMS_COUNT; return roomList[random]; } void addRandomConnection() { struct ROOM A; struct ROOM B; A = getRandomRoom(); do { B = getRandomRoom(); }while(isSameRoom(A, B) == true); //printf("Add Random Connection, 1:%s, 2:%s\n", A.name, B.name); //for testing purposes } Using the print statements I can see that the isSameRoom function isn't working. It's generating random rooms just fine, but there are instances when I run the program that I'm getting the same room for A and B. Any idea why? Thanks! :)
==, you have to usestrcmproomList[1].namethruroomList[7].namefor#define MAX_ROOMS_COUNT 7rooms. In C arrays are indexed from0so that should beroomList[0].namethruroomList[6].name.