第一张图片为报错截图
第二张图片为.h文件中的自定义函数声明
当不分文件全都写在一起时代码能正常运行
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<malloc.h>
#include "final.h"
COU *create_form() //创建链表(便于课程信息的插入和删除)
{
COU *head,*tail,*p;//表头、表尾指针
int num,stime,ttime;//课程编号、总学时、授课学时
int etime,score,term;//实验或上机学时、学分、开课学期
char name[20],kind[10];//课程名称、课程性质
int size=sizeof(COU);
head=tail=NULL;//初始将表头、表尾指针置为空
printf("输入选修课程信息:\n");
scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term);
while(num!=0)
{
p=(COU *)malloc(size);//开辟结构体大小的空间
p->num=num;//给结构体中num变量赋值
strcpy(p->name,name);//将name字符串的内容复制到结构体变量name
strcpy(p->kind,kind);//将kind字符串的内容复制到结构体变量kind
p->stime=stime;
p->ttime=ttime;
p->etime=etime;
p->score=score;
p->term=term;
if(head==NULL) //表头指针指为空
{
head=p; //则将表头指针指向刚赋完值的一个完整结构体的数据域
}
else //表头指针不为空则说明有指向的数据内容
{
tail->next=p;//此时只需控制表尾指针域指向下一个内容的结构体数据域
}
tail=p;
scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term);
}
tail->next=NULL;//当循环结束时将表尾指针的指针域指向空,说明没有后续的数据内容,形成链表
return head;
}
void search() //课程信息查询
{
int a,num;
int t=1;
char type[10],cname[10];
COU *ptr;
L1:system("cls");
printf("\n\n\t\t**********请选择查询方式*************\n");
printf("\n\t\t\t1---按课程名称查找\n");
printf("\n\t\t\t2---按课程性质查找\n");
printf("\n\t\t\t3---按学分查找\n");
printf("\n\t\t\t4---退出查找\n");
printf("\n\n\t\t**************************************\n");
printf("\n\nChiose your number(1-4):");
scanf("%d",&a);
switch(a)
{
case 1:
printf("请输入要查找的课程的名称:");
scanf("%s",cname);
printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n");
for(ptr=head;ptr;ptr=ptr->next)
{
if(strcmp(cname,ptr->name)==0)//字符串比较
{
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,
ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
}
if(t)//t为非零
{
printf("\t\n未找到!\n");
}
t=1;
system("pause");
goto L1;
case 2:
printf("请输入要查找的课程的性质:");
scanf("%s",type);
printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n");
for(ptr=head;ptr;ptr=ptr->next)
{
if(strcmp(type,ptr->kind)==0) //比较字符串
{
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,
ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
}
if(t)
{
printf("\t\n未找到!\n");
}
t=1;
system("pause");
goto L1; //直接跳转到L1执行下面的语句
case 3:
printf("输入要查找的课程的学分:");
scanf("%d",&num);
printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n");
for(ptr=head;ptr;ptr=ptr->next)
{
if(ptr->score==num)
{
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,
ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
}
if(t)
{
printf("\n\t未找到!\n");
}
t=1;
system("pause"); //暂停
goto L1;
case 4:break;
}
}
void *del() //删除课程
{
COU *p1,*p2;
char ch,ch1;
int num;
while(ch!='0')
{
printf("输入想要删除的课程编号:");
scanf("%d",&num);
if(head->num==num)//要删除课程位于第一个节点
{
p2=head;//将链表表头指针head传给p2
head=head->next;//而将head指针域指向的下一个节点传给head,此时链表表头指针变为原来第二个节点的指针
free(p2);//将有第一个节点指针的p2空间释放,此时删除了位于第一个节点的课程
}
if(head==NULL)//头指针为空,链表不存在,课程信息不存在
{
return NULL;
}
p1=head;
p2=head->next;
while(p2)//p2不为空
{
if(p2->num==num)
{
p1->next=p2->next;
free(p2);
}
else
{
p1=p2;
}
p2=p1->next;
}
printf("\n继续删除请按回车\n");
printf("\n结束删除课程按 0:");
ch1=getchar(); //用于接收subj->term输完后输入的回车键
ch=getchar();
printf("\n删除完毕,新信息存入文件中\n");
system("pause");
}
return head;
system("pause");
}
#define CHOOSE 10//学生能选课程数的最大值
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<malloc.h>
void prin1(); //声明浏览学生所有选修课程函数
void choose(); //声明学生选课函数
typedef struct subjects //定义结构体叫作COU,在后面就可以直接使用
{
int num; //课程编号
char name[30]; //课程名称
char kind[20]; //课程性质
int stime; //总学时
int ttime; //授课学时
int etime; //实验或上机学时
int score; //学分
int term; //开课学期
struct subjects *next;
}COU;
COU *head=NULL;
void Mangers(); //管理员菜单
void Students(); //学生菜单
void savefile(); //保存管理员文件
void savefile1() //保存学生文件
void *insert();
COU *create_form();
void*BasicInsert(COU *subj);
void readfile();
void prin();
void *del();
void search();
void About();
void Help();