是不是缺少头文件
#include<stdio.h> /*头文件*/#include<stdlib.h>
#include <conio.h>
#include<string.h>
#define LEN sizeof(struct Student) /*宏定义*/
struct Student /*定义一个结构体数组,包含学生信息*/
{
int num;
char name[15];
char sex[4];
int math, English,physics,Mks,C,teal,PE;
struct Student *next;
};
int n;
void main() /*主函数,选择界面。*/
{
void creat(void);
void save(struct Student *,char []);
struct Student *load(char []);
void enter(void); /*录入函数*/
void search_1(void); /*查询函数_1*/
void search_2(void); /*查询函数_2*/
void modify(void); /*修改函数*/
void back(void); /*退出函数*/
void mune_1(); /*界面-1*/
void mune_2(); /*界面-2*/
mune_1();
mune_2();
printf("\n");
}
void mune_1() /*主函数的辅助函数——mune_1函数。*/
{
printf("\n\n\n\n\n\n");
printf("\t***********************************************************
*");
printf("\t\t\t ********** ********** ");
printf("\t\t\t◇******** 欢 迎 使 用 班 级 考 勤 系 统
********◇");
printf("\t\t\t ********** ********** ");
printf("\n\t************************************************************\n\n\n");
printf("================================================================================");
printf("\n\n\n\t\t\t\t<按任意键进入>\n\t\t\t\t\t");
getch();
system("cls");
}
void mune_2()
{
int option,ch; /*定义一个选项的数据类型*/
printf("\n\n\n"); /*制作的一个漂亮的选择界面*/
printf("\t***************************************************************\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* 1、录入本次课考勤情况\t 2、查询学生考勤信息\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* 3、创建学生信息\t\t 4、修改学生信息\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* 5、查看班级考勤情况 \t 6、退出考勤系统\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t***************************************************************\n");
printf("\n");
printf("\t\t\t请输入您所需的操作(1~6):\n\t\t\t\t");
while(1)
{
scanf("%d",&option);
switch(option)
{
case 1: {ch=getchar();system("cls");enter();}break;
case 2: {ch=getchar();system("cls");search_1();}break;
case 3: {ch=getchar();system("cls");creat();}break;
case 4: {ch=getchar();system("cls");modify();}break;
case 5: {ch=getchar();system("cls");search_2();}break;
case 6: {ch=getchar();system("cls");back();}break;
default: printf("\t\t\t输入错误,请重新输入!!!"); }
printf("\n\t\t\t\t");
}
ch=getchar();
}
void save(struct Student *head,char filename[])
{
FILE *fp;
struct Student *p=head;
if((fp=fopen(filename,"wb"))==NULL)
{
printf("can not open file\n");
exit(0);
}
while(p!=NULL)
{
fwrite(p,LEN,1,fp);
p=p->next;
}
fclose(fp);
}
struct Student *load(char filename[])
{
FILE *fp;
struct Student *head,*p1,*p2;
head=NULL;
p1=NULL;
if((fp=fopen(filename,"rb"))==NULL)
{
printf("can not open file\n");
exit(0);
}
while(!feof(fp))
{
p2=(struct Student *)malloc(LEN);
if(fread(p2,LEN,1,fp)==1)
{
if(head==NULL)
head=p2;
if(p1)
p1->next=p2;
p1=p2;
}
}
p1->next=NULL;
return (head);
}
void enter() /*录入函数*/
{
struct Student *head,*p;
char select='y',cla[10];
int sub,stu,num,flag=0;
printf("请输入上课班级:");
scanf("%s",cla);
strcat(cla,".dat");
p=head=load(cla);
system("cls");
while(select=='y'||select=='Y')
{
printf("\n\n\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* 1、复变 \t\t 2、大学英语\t\t *\n"); printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* 3、电拖 \t\t 4、马克思基本原理概论 *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* 5、C程序设计基础 \t 6、模电\t\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* 7、体育\t\t\t\t\t\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t*\t\t\t\t\t\t\t *\n");
printf("\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("\n");
printf("\t\t\t请输入科目选项(1~7):\n\t\t\t\t");
scanf("%d",&sub);
while(1)
{
if(sub>0&&sub<8)
break;
else
printf("\t\t\t输入错误,请重新输入\n\t\t\t\t"); scanf("%d",&sub);
}
system("cls");
printf("请输入本次课缺席同学的学号:");
scanf("%d",&stu);
printf("\n");
printf("请输入该同学的缺课节数:");
scanf("%d",&num);
while(p!=NULL)
{
if(p->num==stu)
switch(sub)
{
case 1: {p->math+=num;}break;
case 2: {p->English+=num;}break;
case 3: {p->physics+=num;}break;
case 4: {p->Mks+=num;}break;
case 5: {p->C+=num;}break;
case 6: {p->teal+=num;}break;
case 7: {p->PE+=num;}break;
}
p=p->next;
}
printf("\n\n\t\t******输入成功******!!!\n");
printf("是否继续输入(y\\n):");
scanf("%c",&select);
}
save(head,cla);
getch();
system("cls");
mune_2();
}
void search_1(void) /*查询个人信息*/
{
struct Student *head,*p;
char select='y',cla[10];
int num,flag=0;
printf("请输入上课班级:");
scanf("%s",cla);
strcat(cla,".dat");
p=head=load(cla);
printf("请输入要查询同学的学号:");
scanf("%d",&num);
system("cls");
while(p!=NULL)
{
if(p->num==num)
{
printf("\n\n");
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf(" 学号 姓名 性别 复变 英语 电拖 马克思 C语言 模电 体育\n");
printf(" %3d %8s %4s%5d %5d %5d %5d %3d %7d %8d\n",p->num,p->name,p->sex,
p->math,p->English,p->physics,p->Mks,p->C,p->teal,p->PE);
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
flag=1;
}
p=p->next;
}
if(flag==0)
printf("\t\t!!!没有这个学生信息,请核对后再输入!!!\n\n"); getch();
system("cls");
mune_2();
}
void search_2(void) /*查询某班级信息*/
{
char cla[10];
struct Student *head,*p;
printf("请输入您要查询的班级名:");
gets(cla);
system("cls");
printf("\n \t\t\t%s班的考勤情况\n\n",cla);
strcat(cla,".dat");
p=head=load(cla);
printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf(" 学号 姓名 性别 复变 英语 电拖 马克思 C语言 模电 体育\n");
while(p!=NULL)
{
printf(" %3d %8s %4s%5d %5d %5d %5d %3d %7d %8d\n",p->num,p->name,p->sex,
p->math,p->English,p->physics,p->Mks,p->C,p->teal,p->PE); p=p->next;
}
printf("\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
getch();
system("cls");
mune_2();
}
void modify(void) /*修改函数*/ {
int a,flag=0;
char cla[10];
struct Student *head,*p;
printf("\n\t\t请输入要修改的班级:");
scanf("%s",cla);
strcat(cla,".dat");
p=head=load(cla);
printf("\n\t\t请输入要修改的学生的学号:");
scanf("%d",&a);
while(p!=NULL)
{
if(p->num==a)
{
printf("\n\t\t请重新输入复变函数缺勤节数:");
scanf("%d",&p->math);
printf("\n\t\t请重新输入大学英语缺勤节数:");
scanf("%d",&p->English);
printf("\n\t\t请输入电机拖动缺勤节数:");
scanf("%d",&p->physics);
printf("\n\t\t请重新输入马克思主义基本原理与概论缺勤节数:");
scanf("%d",&p->Mks);
printf("\n\t\t请重新输入C语言缺勤节数:");
scanf("%d",&p->C);
printf("\n\t\t请重新输入模电缺勤节数:");
scanf("%d",&p->teal);
printf("\n\t\t请重新输入体育缺勤节数目:");
scanf("%d",&p->PE);
flag=1;
save(head,cla);
printf("\n\t\t修改成功!\n\t\t");
break;
}
p=p->next;
}
if(flag==0)
{
printf("\t\t!!!没有这个学生信息,请核对后再输入!!!\n\n"); }
getch();
system("cls");
mune_2();
}
void creat(void) /*创建函数*/
{
FILE *fp;
struct Student *head,*p,*p1,*p2;
char filename[10];
n=0;
p1=p2=(struct Student *)malloc(LEN);
printf("请输入你要创建班级的名称(如果要创建的文件已存在,将覆盖原文件):");
gets(filename);
strcat(filename,".dat");
if((fp=fopen(filename,"wb"))==NULL)
{
printf("can not open file\n");
exit(0);
}
printf("请输入学生的基本信息:姓名、学号、性别\n");
scanf("%s%d%s",p1->name,&p1->num,p1->sex);
p1->math=p1->English=p1->physics=p1->Mks=p1->C=p1->teal=p1->PE=0;
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)
head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Student *)malloc(LEN);
scanf("%s%d%s",p1->name,&p1->num,p1->sex);
p1->math=p1->English=p1->physics=p1->Mks=p1->C=p1->teal=p1->PE=0; }
p2->next=NULL;
p=head;
while(p!=NULL)
{
fwrite(p,LEN,1,fp);
p=p->next;
}
fclose(fp);
printf("\t\t\t创建成功,按任意键返回主菜单\n");
getch();
system("cls");
mune_2();
}
void back(void) /*退出函数*/
{
printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t感谢您的使用~\n\t\t\t\t "); getch();
exit(0);
}