网上找的
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
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 *create_form()
{
SUB *head,*tail,*p;
int num,stime,ttime;
int etime,score,term;
char name[20],kind[10];
int size=sizeof(SUB);
head=tail=NULL;
printf("输入选修课程信息:\n");
scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&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=p;
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 savefile(SUB *head)
{
SUB *p;
FILE *fp;
fp=fopen("subjects.txt","w");
fprintf(fp,"课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期\n");
for(p=head;p;p=p->next)
fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term);
fclose(fp);
}