C和ncurses中的结构数组

时间:2014-03-14 17:22:25

标签: c ncurses

我正在尝试设置一个结构数组,最终将使用ncurses打印掉6个框。第一个问题是我不知道如何设置结构数组,我的第二个问题是,我不知道我应该如何绘制框。关于盒子的额外事情是它们必须使用“|”绘制垂直墙的钥匙,我需要使用“ - ”水平的墙壁。我已经尝试使用malloc内存来获取结构数组:

room * roomInfo = malloc(sizeof(room) * 6);

房间是我的结构名称,roomInfo是我的结构数组。我有三个错误。一个是“错误:未知类型名称'房间'”,另一个是“错误:'房间'未声明(在此功能中首次使用)”(在我的文件顶部我有:“struct room roomInfo;”)和第三个是“注意:每个未声明的标识符仅针对它出现在”

中的每个函数报告一次
typedef struct 
{
int roomNumber;
int height;
int width;
int eastDoor;
int westDoor;
int southDoor;
int northDoor;
}room;

1 个答案:

答案 0 :(得分:0)

不确定你做错了什么:以下最小代码编译没有错误:

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

typedef struct
{
int roomNumber;
int height;
int width;
int eastDoor;
int westDoor;
int southDoor;
int northDoor;
}room;

int main(void) {
room *roomInfo;
roomInfo = malloc(6*sizeof *roomInfo);
}

最有可能的是:在您声明room时,您的room *roomInfo;定义尚不清楚。它在#include吗?