#include "stdio.h" #include "string.h" #include "stdlib.h" #include "malloc.h" void prin1(); void choose(); typedef struct subjects { int num; char name[20]; char kind[10]; int stime; int ttime; int etime; int score; int term; struct subjects *next; }sub; sub *head=NULL; sub *create_form() { sub *head,*tail,*p; int num,stime,ttime; int etime,score,term; char name[20],kind[10]; int size=tail==NULL; printf("输入选修课程信息:\n"); scanf("%d%s%s%d%d%d%d%d",&num,&name,&kind,&stime,&ttime,&etime,&term); while(num!=0) { p=(sub *)malloc(size); p->num=num; strcpy(p->name,name); strcpy(p->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=NULL; 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 savefile1() { sub *p; FILE *fp; fp=fopen("3.txt","w"); if(fp==NULL)exit(0); for(p=head;p;p->next) fprintf(fp,"%5d%12d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term); fclose(fp); printf("创建后的信息已放入'3.txt'文件中\n"); system("pause"); } void readfile() { void *myInsert(sub*); sub *newSub; int num,stime,ttime,etime; int score,term; char c,name[20],kind[10],fname[20]; FILE *fp; fp=fopen("3.txt","r"); while(!feof(fp)) { newSub=(sub*)malloc(sizeof(sub)); fscanf(fp,"%d%s%s%d%d%d%d%d\n",&newSub->num,&newSub->name,&newSub->kind,&newSub->stime,&newSub->ttime,&newSub->etime,&newSub->score,&newSub->term); myInsert(newSub); } fclose(fp); } void prin() { sub *ptr; head=NULL; readfile(); printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开学学期\n"); }