您好,欢迎光临本网站![请登录][注册会员]  
文件名称: struct student
  所属分类: Java
  开发工具:
  文件大小: 5kb
  下载次数: 0
  上传时间: 2010-11-13
  提 供 者: weij*****
 详细说明: #include"stdio.h" #include"stdlib.h" #define NULL 0 struct student { long num; char name[20]; int score[6]; struct student *next; }; void show() { printf("\nthere is a cataloge as follow.\n"); printf("***************************************\n"); printf("* *\n"); printf("* 1. create *\n"); printf("* 2. Insert *\n"); printf("* 3. print *\n&quo t;); printf("* 4. delete *\n"); printf("* 5. modify *\n"); printf("* 6. save_to_file *\n"); printf("* 7. lode from file *\n"); printf("* 8. exit *\n"); printf("***************************************\n"); printf("please input 1--8 to choice what you want:\n"); } struct student *create() { struct student *head,*p,*last; int i; int temp2; char name[20]; p=head=(struct student *)malloc(sizeof(struct student)); head->next=NULL; last=p; while(1) { last->next=p; last=p; p=(struct student *)malloc(sizeof(struct student)); /*last->next=p; last=p;*/ p->next=NULL; printf("number:"); scanf("%ld",&p->num); if(p->num==0)break; getchar(); printf("name:"); scanf("%s",p->name); printf("score:"); for(i=0;i<6;i++) { scanf("%d",&temp2); p->score[i]=temp2; } printf("next student's information.\n"); } free(p); return head; } void Insert(struct student *head) { struct student *p,*q; int score; long num; int i; printf("\nEnter the student's information you want to insert.\n"); printf("number:"); scanf("%ld",&num); q->num=num; getchar(); printf("name:"); scanf("%s",q->name); printf("score:(chinese,math,english,biology,physics,chemistry)\n"); for(i=0;i<6;i++) { scanf("%d",&score); q->score[i]=score; } q->next=NULL; p=head; while(p->next->numnum&&p->next!=NULL) p=p->next; q->next=p->next; p->next=q; if(p->next==NULL) p->next=q; } void delete(struct student *head) { struct student *p,*q; long num; printf("enter the student's information you want to delete.\n"); printf("number:"); scanf("%ld",&num); getchar(); p=head; while(p->next!=NULL&&p->next->num!=num) p=p->next; q=p->next; p->next=p->next->next; free(q); } void print(struct student *head) { struct student *p; int i; p=head->next; if(p==NULL) { printf("\nthere is no information.\n"); exit(0); } printf("\nnumber\tnamme\tchinese\tmath\tenglish\tbiology\tphysics\tchemistry\n"); while(p!=NULL) { printf("\n%ld\t%s",p->num,p->name); for(i=0;i<6;i++) printf("\t%d",p->score[i]); p=p->next; } } void modify(struct student *head) { struct student *p; int choice,i; long num; char name[20]; int score[6]; printf("\nEnter what student's information you want to modify.\n"); printf("number:"); scanf("%ld",&num); getchar(); printf("\nname:"); scanf("%s",name); printf("\n"); p=head->next; while(p->num!=num&&p->name[20]!=name[20]&&p!=NULL) p=p->next; printf("\nplease choice what you want to modify:1-number 2-name 3-score.\n"); scanf("%d",&choice); switch(choice) { case 1:printf("\nEnter the true number:"); scanf("%ld",&num); p->num=num; break; case 2:printf("\nEnter the true name:"); scanf("%s",p->name); break; case 3:printf("\nEnter the right score:"); for(i=0;i<6;i++) { scanf("%d",&score[i]); p->score[i]=score[i]; } break; } } void save_in(struct student *head) { struct student *p; FILE *fp; char file_name[30]; printf("please enter the file name you want to save.\n"); scanf("%s",file_name); printf("save to file:%s",file_name); if((fp=fopen(file_name,"w"))==NULL) { printf("can't open the file.\n"); exit(0); } p=head; while(p->next!=NULL) { fwrite((void*)p->next,sizeof(struct student),1,fp); p=p->next; } fclose(fp); } struct student *load_from_file() { struct student *head,*p,*last; FILE *fp; char file_name[30]; head=(struct student *)malloc(sizeof(struct student)); last=head; head->next=NULL; printf("please enter the file name you want to save.\n"); scanf("%s",file_name); printf("save to file:%s",file_name); if((fp=fopen(file_name,"r"))==NULL) { printf("can't open the file.\n"); exit(0); } p=(struct student *)malloc(sizeof(struct student)); p->next=NULL; while(fp=fread((void *)p,sizeof(struct student),1,fp)==1) { last->next=p; last=p; p=(struct student *)malloc(sizeof(struct student)); p->next=NULL; } free(p); fclose(fp); return head; } void main() { struct student *la; int choice; /*char Yes_No;*/ la=(struct student *)malloc(sizeof(struct student)); la->next=NULL; while(1) { show(); scanf("%d",&choice); switch(choice) { case 1:la=create(); break; case 2:Insert(la); break; case 3:print(la); break; case 4:delete(la); break; case 5:modify(la); break; case 6:save_in(la); break; case 7:la=load_from_file(); break; case 8:exit(0); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: struct student
 输入关键字,在本站1000多万海量源码库中尽情搜索: