发布网友
共1个回答
热心网友
网上找的
#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);
}
void savefileadd(SUB *head)
{
SUB *p;
FILE *fp;
fp=fopen("subjectsadd.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);
}
void savefiledel(SUB *head)
{
SUB *p;
FILE *fp;
fp=fopen("subjectsdel.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);
}
void prin(SUB *head)
{
SUB *ptr;
if(head==NULL){
printf("NO RECORDS!\n");
return;
}
printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n");
for(ptr=head;ptr;ptr=ptr->next)
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
}
void search(SUB *head)
{
int a,num;
int t=1;
char type[10];
char ch='a',ch1;
SUB *ptr;
while(ch!=' '){
printf("若要按课程性质查找请输入1,若要按学分查找请输入2:\n");
scanf("%d",&a);
switch(a){
case 1:printf("请输入要查找的课程的性质:\n");
scanf("%s",type);
printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n");
参考资料:转自http://tieba.baidu.com/f?kz=159785433