#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "malloc.h"
typedef struct student
{ char num[10];
char name[10];
char sex;
char call[15];
char bir[8];
int room[5];
char home[50];
int s[3];
struct student *next;
}student;
void modify(struct student *head);
void zhujiemian();
void search(student *head);
struct student *creat();
void print(student*head);
void save(student *head);
void load();
struct student * move(struct student * head)
void main()
{ int b;
struct student *head;
printf(" ***********************************\n");
printf(" infomation of student\n");
printf(" ***********************************\n\n\n\n\n");
printf(" 1 input imformation\n");
printf(" 2 look for imformation\n");
printf(" 3 modify imformation\n");
printf(" 4 print all imformation\n");
printf(" 5 remove imformation\n");
printf(" 6 open file\n");
printf(" 8 save file\n");
printf(" 9 exit\n\n\n\n\n");
printf(" ***********************************\n");
{printf(" please enter what you want to do:");
scanf("%d",b);
switch(b)
{
case 1:head=creat();break;
case 2:search(head);break;
case 3:modify(head);break;
case 4:print(head);break;
case 5:head=move(head);break;
case 6:load();break;
case 7:save(head);break;
case 8:exit(0);
}
}
}
student *creat()
{
int i=1,a;
struct student *head=0,*p,*pp;
printf("请输入你要输入学生信息的 人数:");
scanf("%d",&a);
p=pp=(student*)malloc(sizeof(student));
printf("please put in students' number,name,xingbie(M/F),call,birthday(19900101),\nroom number,homeaddress,score ofmath,english and physic(89,56,90):");
scanf("%s%s%s%s%s%s%s%c%c%c",p->num,p->name,p->sex,p->call,p->bir,p->room,p->home,p->s[0],p->s[1],p->s[2]);
head=p;
while(a!=i)
{i=i++;
pp=p;
pp->next=p;
p=(student*)malloc(sizeof(student));
scanf("%s%s%s%s%s%s%s%c%c%c",p->num,p->name,p->sex,p->call,p->bir,p->room,p->home,p->s[0],p->s[1],p->s[2]);
}
pp->next=0;
return(head);
}
void search( student *head)
{student *p;
char s[15];
printf("please enter the name or number you want to search\n");
scanf("%s",s);
p=head;
while((strcmp(p->num,s)||strcmp(p->name,s))&&p!=0)
p=p->next;
if(p==0)
printf("no imformation");
else
{ printf(" find the follow imfomation:\n");
printf("num||name||xingbie||call||birthday||roomnumber||homeadress||math||english||physicy\n");
printf("%s||%s||%s||%s||%s||%s||%s||%c||%c||%c",p->num,p->name,p->sex,p->call,p->bir,p->room,p->home,p->s[0],p->s[1],p->s[2]);
}
printf("press any key back and enter to menu");
scanf("%c",a);
}
void print( struct student*head)
{
struct student*p;
p=head;
printf(" **********student'imformation **********\n");
printf("num name xingbie call birthday roomnumber homeadress math english physicy\n");
while(p!=0)
{
printf("%15s%10s,%7s,%15s,%10s,%11s,%50s,%5d,%5d,%5d\n",p->num,p->name,p->sex,p->call,p->bir,p->room,p->home,p->s[0],p->s[1],p->s[2]);
p=p->next;
}
printf(" **********end********** ");
}
void modify(struct student *head)
{struct student *p,*pp;
char c,d;
printf("please enter the name or the number of the student you want to modify \n");
scanf("%s",c);
p=head;
while((strcmp(p->num,c)||strcmp(p->name,c))&&p!=0);
{ pp=p;
p=p->next;
}
printf("what do you want to modify?(num,name,xingbie,dianhua,birthday,sushe,home,math,english,physics)");
scanf("%s",d);
if (!strcmp(d,"number"))
{printf("please enter the number :\n");
scanf("%s",p->num);
}
else if (!strcmp(d,"home"))
{printf("please enter the number :\n");
scanf("%s",p->home);
}
else if (!strcmp(d,"xingbie"))
{printf("please enter the number :\n");
scanf("%s",p->sex);
}
else if (!strcmp(d,"dianhua"))
{printf("please enter the number :\n");
scanf("%s",p->call);
}
else if (!strcmp(d,"birthday"))
{printf("please enter the number :\n");
scanf("%s",p->bir);
}
else if (!strcmp(d,"sushe"))
{printf("please enter the number :\n");
scanf("%s",p->room);
}
else if (!strcmp(d,"home"))
{printf("please enter the number :\n");
scanf("%s",p->home);
}
else if (strcmp(d,"math")!=0)
{printf("please enter the number :\n");
scanf("%s",p->s[0]);
}
else if (!strcmp(d,"english"))
{printf("please enter the number :\n");
scanf("%s",p->s[1]);
}
else (!strcmp(d,"physic"))
{
printf("please enter the number :\n");
scanf("%s",p->s[2]);
}
}
void save( student *head)
{FILE *fp;
struct student *p;
char f[10];
printf("enter the file name\n");
scanf("%s",f);
fp=fopen(f,"wb+")==0;
p=head;
while (p!=0)
{
fwrite(p,sizeof(student),1,fp);
p=p->next;
}
fclose(fp);
}
void load()
{
struct student *p,*pp,*head=0;
FILE *fp;
char file[10];
printf("enter the file name :\n");
scanf("%s",file);
if((fp=fopen(file,"rb+"))==0)
{printf("no this file");
exit(0);
}
p=head;
while (!feof(fp))
{
fread(p,sizeof(student),1,fp);
p=p->next;
}
fclose(fp);
}
struct student * move(struct student * head)
{
char s[10];
char a;
struct student * p,* pp;
printf("please enter remove number or name:\n");
scanf("%s",s);
p=pp=head;
while ((strcmp(p->num,s)||strcmp(p->name,s))&&p!=0)
{ pp=p;
p=p->next;
}
if(p==0)
printf("no imfomation");
else
{ printf("find the follow imfomation:\n");
printf("num||name||xingbie||call||birthday||roomnumber||homeadress||math||english||physicy\n");
printf("%s,%s,%s,%s,%s,%s,%s,%c,%c,%c",p->num,p->name,p->sex,p->call,p->bir,p->room,p->home,p->s[0],p->s[1],p->s[2]);
printf(" press 'y' to continnue ");
scanf("%d",a);
if( a!='y') printf("no imfomation");
else if(p==head) head=p->next;
else pp->next= p->next;
printf("don't forget to save ");
}
return(head);
}