该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
return 1;
}
}
p=p->next;
} while(p!=NULL);
return 0;
}
void m_exit() /*退出*/
{
int option=0;
printf("\n\n\tAre you sure to exit?\n");
printf("\n\n\t1.YES");
printf("\n\n\t2.NO\n\t");
scanf("%d",&option);
if(option==1) exit(0);
else
return;
}
void creat() /*读取como.dat内容,并创建链表a*/
{
FILE *fp;
int n=0,i,tag=0;
struct student_type temp_stud;
struct stunode_type *p1,*p2;
p1=p2=stu_head=(struct stunode_type*)malloc(sizeof(struct stunode_type));
stu_head->next=NULL;
if((fp=fopen("c:\\COMO.DAT","rb"))==NULL)/*第一次como.dat不存在,创建*/
{ tag=1;
fp=fopen("c:\\COMO.DAT","wb");
fclose(fp);
}
if(tag==1){free(p1); stu_head=NULL;return;}
fp=fopen("c:\\COMO.DAT","rb");
/*else /*读取数据,构成链表*/
fread(&n,sizeof(int),1,fp);
total=n;
for(i=0;i
{
fread(&temp_stud,sizeof(struct student_type),1,fp);
strcpy(p1->nostudent,temp_stud.nostudent);
strcpy(p1->name,temp_stud.name);
strcpy(p1->department,temp_stud.department);
p1->type=temp_stud.type;
p1->time=temp_stud.time;
if(i
{
p1=(struct stunode_type*)malloc(sizeof(struct stunode_type));
p2->next=p1;
p2=p2->next;
}
}
p2->next=NULL;
fclose(fp);
}
void save()
{
FILE *fp;
struct student_type student;
struct stunode_type *p1=stu_head;
fp=fopen("c:\\COMO.DAT","wb");
fwrite(&total,sizeof(int),1,fp);
do
{
strcpy(student.nostudent,p1->nostudent);
strcpy(student.name,p1->name);
strcpy(student.department,p1->department);
student.type=p1->type;
student.time=p1->time;
fwrite(&student,sizeof(struct student_type),1,fp);
p1=p1->next;
}
while(p1!=NULL);
fclose(fp);
}
void list_student()/*列出所有注册的学生*/
{
struct stunode_type *p=stu_head;
if(stu_head==NULL){ printf("\n\n\t the student list is NULL");return;}
printf("the all students are as follows\n");
while(p!=NULL)
{ printf("\n\n\tnostudent:%s\n",p->nostudent);
printf("\n\n\tname:%s",p->name);
printf("\n\n\tdepartment:%s",p->department);
printf("\n\n\ttime:%d",p->time);
p=p->next;
}
}
void main()
{ char option;
char tm_nostudent[5];
creat();
do
{printf("\n\t***********************************************\n");
printf("\n\n\tWELCOME TO USE JIFANG MANAGE SYSTEM\n");
printf("\n\t**********************************************\n");
printf("\n\n\t\tPlease make a choice below:");
printf("\n\t\t1.Add new student imformation");
printf("\n\t\t2.Shang Ji");
printf("\n\t\t3.Xia ji");
printf("\n\t\t4.Add Time");
printf("\n\t\t5.Search the student's imformation");
printf("\n\t\t6.List all student");
printf("\n\t\t7.Exit");
printf("\n\n\n");
printf("\tInput Your Choice:");
option=getche();
switch(option)
{ case '1': addstudent(); break;
case '2': shangji(); break;
case '3': xiaji(); break;
case '4': addtime(); break;
case '5':
{ printf("\n\n\tplease input the number of the student you want to search\n");
printf("\n\n\tnumber:");
scanf("%s",tm_nostudent);
if(!search(2,tm_nostudent)) printf("\n\n\t the student is not exist!");
break;
}
case '6': list_student();break;
case '7': m_exit(); break;
default:
printf("\n\t********************************************\n");
printf("\n\t The num should 1-7! \n");
printf("\n\t********************************************\n");
break;
}
}while(1);
}