将用户输入的数据连接到Structs中的数组

时间:2017-02-01 03:29:49

标签: c pointers struct scanf

我在C中创建一个基于文本的游戏,它使用用户输入来确定房间和生物。房间最多只能有4扇门,向东南和向西,生物最终将与房间相关联,我希望将用户输入并将其存储在我的结构阵列中,作为轻松连接房间的一种方式和生物。

 #include <cstdlib>
 #include <stdio.h>
 #include <stdlib.h>

using namespace std;

/*
 * 
 */

struct Rooms {
  int roomProperties[5];
};

struct Creatures {
  int creatureProperties[2];
};

int main(int argc, char** argv) {

  //creates rooms from user input
  int roomNums;

  printf("Enter rooms ");
  scanf("%d", &roomNums);
  printf("rooms declared %d\n", roomNums);

  //defines room properties with correlation to numbers entered
  int roomState;
  int northRoom;
  int southRoom;
  int eastRoom;
  int westRoom;

  //cycles for input until properties = # of rooms
  for (int i = 0; i < roomNums; i++) {
    scanf("%d %d %d %d %d", &roomState, &northRoom, &southRoom,    &eastRoom, &westRoom);
    printf("stuff declared %d, %d, %d, %d, %d\n", roomState, northRoom, southRoom, eastRoom, westRoom);
  }

//spawns creatures based on user input

  int monsterCount;
  printf("Enter Monsters ");
  scanf("%d", &monsterCount);
  printf("monsters declared %d\n", monsterCount);

  //creature properties with correlation to numbers entered
  int creatureType;
  int creatureLocation;

  //prompts for information to match creatures spawned
  for (int j = 0; j < monsterCount; j++) {
    scanf("%d %d", &creatureType, &creatureLocation);
    printf("monster stuff %d, %d\n", creatureType, creatureLocation);
  }

  return 0;
}

我正在尝试将roomStatenorthRoomsouthRoomeastRoomwestRoom连接到结构Rooms,特别是{{1 } - &gt; roomState,等等。我不知道该怎么做。

0 个答案:

没有答案