You'll definitely want to create a stuct that can hold all the data about a specific area (name, description, neighboring areas, items that are there, commands that can be issued there, etc).
To begin with you can have a huge array of all these areas, as this is simple and will let you focus on learning about structs, and you can just have one function that allocates everything at the start of the game. Later on, you can learn how to dynamically allocate everything into a list.
You'll probably want to start with an array of strings (the C type of string) for commands, and one for items, and then your area struct can just store which indexes of these arrays are applicable.
By having all the areas stored in a struct array, you can now have just one game loop that only need to know the current area and which will work with all areas. And instead of having to have a menu for each area where he user types a number, they can type a command, and you can match that against the commands allowed for each area.
To help get you started, I've written a short example. It only has a few areas and a very small set of commands, but it should be enough for you to build on. As I mentioned earlier, they way this is allocating the data is not ideal (it will be fine for a very small game, but will quickly become cumbersome if you want to keep adding areas), but you can improve on that later.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct area {
char name[20];
char description[200];
int neighbours[4];
int num_items;
int *items;
int num_commands;
int *commands;
} area;
typedef enum {NORTH, EAST, SOUTH, WEST} directions;
area locations[5];
char items[5][20];
char commands[3][20]; // special commands that can only be performed in some areas
void populate_items();
void populate_commands();
void populate_areas();
int main() {
populate_items();
populate_commands();
populate_areas();
int current_area = 0;
int exit_status = 0;
char command[20];
while (exit_status == 0) {
printf("\nYou are at %s\n", locations[current_area].name);
scanf("%20s", command);
if (strncmp(command, "quit", 20) == 0)
exit_status = 1;
else if (strncmp(command, "look", 20) == 0)
printf("%s\n", locations[current_area].description);
else if (strncmp(command, "search", 20) == 0) {
if (locations[current_area].num_items > 0) {
printf("You find:\n");
for (int n = 0; n < locations[current_area].num_items; n++)
printf("%s\n", items[locations[current_area].items[n]]);
}
else
printf("There is nothing here.\n");
}
else if (strncmp(command, "north", 20) == 0) {
if (locations[current_area].neighbours[NORTH] != -1)
current_area = locations[current_area].neighbours[NORTH];
else
printf("You can't go that way.\n");
}
else if (strncmp(command, "east", 20) == 0) {
if (locations[current_area].neighbours[EAST] != -1)
current_area = locations[current_area].neighbours[EAST];
else
printf("You can't go that way.\n");
}
else if (strncmp(command, "south", 20) == 0) {
if (locations[current_area].neighbours[SOUTH] != -1)
current_area = locations[current_area].neighbours[SOUTH];
else
printf("You can't go that way.\n");
}
else if (strncmp(command, "west", 20) == 0) {
if (locations[current_area].neighbours[WEST] != -1)
current_area = locations[current_area].neighbours[WEST];
else
printf("You can't go that way.\n");
}
}
return 0;
}
void populate_items() {
strncpy(items[0], "shell", sizeof items[0]);
strncpy(items[1], "branch", sizeof items[1]);
strncpy(items[2], "lighter", sizeof items[2]);
strncpy(items[3], "water bottle", sizeof items[3]);
strncpy(items[4], "torch", sizeof items[4]);
return;
}
void populate_commands() {
strncpy(commands[0], "burn", sizeof commands[0]);
strncpy(commands[1], "move", sizeof commands[1]);
strncpy(commands[2], "break", sizeof commands[2]);
return;
}
void populate_areas() {
strncpy(locations[0].name, "the beach", sizeof locations[0].name);
strncpy(locations[0].description, "A sandy beach covered in shells.", sizeof locations[0].description);
memcpy(locations[0].neighbours, (int[]) { -1, 1, -1, -1 }, sizeof locations[0].neighbours);
locations[0].num_items = 1;
locations[0].items = malloc(locations[0].num_items * sizeof(int));
locations[0].items[0] = 0;
locations[0].num_commands = 0;
locations[0].commands = NULL;
strncpy(locations[1].name, "the forest", sizeof locations[0].name);
strncpy(locations[1].description, "A dark and spooky forest.", sizeof locations[0].description);
memcpy(locations[1].neighbours, (int[]) { 2, -1, 4, 0 }, sizeof locations[0].neighbours);
locations[1].num_items = 1;
locations[1].items = malloc(locations[0].num_items * sizeof(int));
locations[1].items[0] = 1;
locations[1].num_commands = 0;
locations[1].commands = NULL;
strncpy(locations[2].name, "the hill", sizeof locations[0].name);
strncpy(locations[2].description, "A windswept hilltop covered in tussock.", sizeof locations[0].description);
memcpy(locations[2].neighbours, (int[]) { -1, 3, 1, -1 }, sizeof locations[0].neighbours);
locations[2].num_items = 2;
locations[2].items = malloc(locations[0].num_items * sizeof(int));
locations[2].items[0] = 2;
locations[2].items[1] = 4;
locations[2].num_commands = 0;
locations[2].commands = NULL;
strncpy(locations[3].name, "the mountain", sizeof locations[0].name);
strncpy(locations[3].description, "A tall lonely mountain.", sizeof locations[0].description);
memcpy(locations[3].neighbours, (int[]) { -1, -1, -1, 2 }, sizeof locations[0].neighbours);
locations[3].num_items = 0;
locations[3].items = NULL;
locations[3].num_commands = 0;
locations[3].commands = NULL;
strncpy(locations[4].name, "the river", sizeof locations[0].name);
strncpy(locations[4].description, "A mighty river, too fierce to cross.", sizeof locations[0].description);
memcpy(locations[4].neighbours, (int[]) { 1, -1, -1, -1 }, sizeof locations[0].neighbours);
locations[4].num_items = 1;
locations[4].items = malloc(locations[0].num_items * sizeof(int));
locations[4].items[0] = 3;
locations[4].num_commands = 0;
locations[4].commands = NULL;
return;
}