I am trying to access the values of struct members inside an array of struct pointers inside of a struct. So I have a struct Room that contains an array of pointers to other Rooms called outboundConnection[]. I keep getting the error
error: request for member ‘name’ in something not a structure or union printf("Connection %i: %s", i, x.outboundConnections[i].name);
My struct is set up like this:
typedef struct
{
char* name; //Name of the room
char type; //Type of room
int numOutboundConnections; //Number of rooms connected
int isSelected;; // 0 means not selected, 1 means selected
struct Room *outboundConnections[6]; //Pointers to rooms connected
} Room;
// Room constructor used for filling roomBank
Room room_init(char* name, int s, int c)
{
Room temp;
temp.name = calloc(16, sizeof(char));
strcpy(temp.name, name);
temp.isSelected = s;
temp.numOutboundConnections = c;
return temp;
}
I am adding connections to the outboundConnections array using this function:
void ConnectRoom(Room *x, Room *y)
{
(*x).outboundConnections[(*x).numOutboundConnections] = malloc(sizeof(Room));
(*x).outboundConnections[(*x).numOutboundConnections] = y;
(*x).numOutboundConnections++;
(*y).outboundConnections[(*y).numOutboundConnections] = malloc(sizeof(Room));
(*y).outboundConnections[(*y).numOutboundConnections] = x;
(*y).numOutboundConnections++;
}
I am having issues with getting the name struct member in the outboundConnections array.
printf("Connection %i: %s", i, x.outboundConnections[i].name);
I have tried using ->name and (*x.outboundConnections[i]).name. I am wondering if I am even correctly assigning Rooms to the outboundConnections array or if my issue is how I am trying to access the member variable.