就是一个 信息系统,func1的功能是信息录入,学号num为零的表示结束录入,主函数就先不谢了,后面有错误信息,前面用结构体录入了学号,名字,性别,年龄,科目成绩
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct student)
#define NULL 0
struct score /*用来记录各科成绩准备后面补充的*/
{
int math;
};
struct student /*声明一个结构体用来记录学生信息*/
{
int num;
char name[20];
char sex;
int age;
struct score subject;
struct student *next;
};
void funct1()
{
printf("请录入学生信息,学号为0代表录入完成\n");
struct student *p1,*p2;
struct student.subject math;
p1=p2=( struct student*) malloc(LEN); /* 从这里开始时想做第一个信息录入*/
printf("请输入学号\n");
scanf("%d",&p1->num);
printf("\n请输入该生姓名");
gets(p1->name);
printf("\n请输入该生性别\n");
for(;p1->sex=='f'||p1->sex=='m';)
{
p1->sex=getchar();
printf( "\nerror,please input again:\n");
}
printf("\n请输入该生年龄\n");
scanf("%d",&p1->age);
printf("\n请输入该生成绩,以逗号隔开\n");
scanf("%f",&p1->subject->math); /*到这里让p1指向第一组数据结束*/
head=NULL;
while (p1->num!=0) /*循环跳出的条件是学号num为零*/
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*) malloc(LEN);
printf("请输入学号\n");
scanf("%d",&p1->num);
printf("\n请输入该生姓名");
gets(p1->name);
printf("\n请输入该生性别\n");
for(;p1->sex=='f'||p1->sex=='m';)
{
p1->sex=getchar();
printf( "\nerror,please input again:\n");
}
printf("\n请输入该生年龄\n");
scanf("%d",&p1->age);
printf("\n请输入该生成绩,以逗号隔开\n");
scanf("%f",&p1->subject->math);
}
p2->next=NULL;
}
以下是错误信息,好像一直都是一个地方出错
:\新建文件夹\student information.c(6) : warning C4005: 'NULL' : macro redefinition
d:\microsoft visual studio\vc98\include\stdio.h(212) : see previous definition of 'NULL'
D:\新建文件夹\student information.c(26) : error C2143: syntax error : missing ';' before 'type'
D:\新建文件夹\student information.c(27) : error C2143: syntax error : missing ';' before 'type'
D:\新建文件夹\student information.c(28) : error C2065: 'p1' : undeclared identifier
D:\新建文件夹\student information.c(28) : error C2065: 'p2' : undeclared identifier
D:\新建文件夹\student information.c(28) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct student *'
D:\新建文件夹\student information.c(30) : error C2223: left of '->num' must point to struct/union
D:\新建文件夹\student information.c(32) : error C2223: left of '->name' must point to struct/union
D:\新建文件夹\student information.c(32) : error C2198: 'gets' : too few actual parameters