Lets say I have a program with a struct
typedef struct Room { char* name; struct Room * North; struct Room * South; struct Room * East; struct Room * West; struct Item * itemList; char *character[10]; } Room; And I have to create a bunch of them, as well as dynamically allocate memory for them. As I am new to this, there might be some obvious answers that I might not have known, but how can I assign memory to these structs, while also assigning values to them at once? I know there are ways to do so by declaring a pointer and then manually assigning data using ->, but I want to use the format I have given below, as it would be difficult to assign data one value at a time.
struct Room* room1p = (struct Room*) malloc(sizeof(struct Room)); struct Room* room2p = (struct Room*) malloc(sizeof(struct Room)); struct Room* room3p = (struct Room*) malloc(sizeof(struct Room)); struct Room room1, room2, room3; room1 = (Room){roomList[1], NULL, &room3, &room2, NULL, itemRoom1, charList[1]}; room2 = (Room){roomList[2], NULL, &room2, &room3, &room1, itemRoom2, charList[2]}; room3 = (Room){roomList[3], NULL, &room1, NULL, &room2, itemRoom3, charList[3]};
calloc, which clears memory. Write a loop or a function to do this.