最近在自学C语言,小白求教,大神勿喷
以下是我做的一个书上例题的C语言小程序,
利用结构体编写一个通讯录,输入姓名电话,然后输出这些信息。
我做了一点改变,struct notebook man[n];,程序本来是struct notebook man[NUM],(定义#define NUM 10).
我想输入人数,来确定通讯录中的人数(例题中是10人)。这里是什么问题呢??求教!!!
输出错误如下:
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(12) : error C2143: syntax error : missing ';' before 'type'
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(16) : error C2065: 'man' : undeclared identifier
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(16) : error C2109: subscript requires array or pointer type
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(16) : error C2224: left of '.name' must have struct/union type
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(16) : error C2198: 'gets' : too few actual parameters
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(18) : error C2109: subscript requires array or pointer type
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(18) : error C2224: left of '.num' must have struct/union type
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(18) : error C2198: 'gets' : too few actual parameters
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(22) : error C2109: subscript requires array or pointer type
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(22) : error C2224: left of '.name' must have struct/union type
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(22) : error C2109: subscript requires array or pointer type
D:\软件学习\c语言\2019.7暑假\结构体通讯录.c(22) : error C2224: left of '.num' must have struct/union type
执行 cl.exe 时出错.
结构体通讯录.obj - 1 error(s), 0 warning(s)
#include
struct notebook
{
char name[20];
char num[20];
};
main()
{
int n,i;
printf("请输入人数:");
scanf("%d",&n);
struct notebook man[n];
for(i=0;i
{
printf("请输入姓名:\n");
gets(man.name);
printf("请输入电话:\n");
gets(man.num);
}
for(i=0;i
{
printf("姓名为:%s\t\t电话为%s\n",man.name,man.num);
}
}