69,373
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Course
{
char sno[10];
char cno[10];
char cname[10];
int xuefen;
int biaoji;
struct Course * next;
};
int count[2][2]={{45,0},{45,0}};
void main()
{
FILE*fp;
struct Course *p1,*p2,*head;
if((fp=fopen("sc.txt","r"))==NULL)
{
printf("open file error!\n");
exit(0);
}
p1=head=(struct Course*)malloc(sizeof(struct Course));
p1=head;
//head = p1;
fscanf(fp,"%s%s%s%d%d",p1->sno,p1->cno,p1->cname,&p1->xuefen,&p1->biaoji);
while(!feof(fp))
{
printf("1. %s %s %s %d %d \n",p1->sno,p1->cno,p1->cname,p1->xuefen,p1->biaoji);
p1 = p1->next =(struct Course*)malloc(sizeof(struct Course));//-------
fscanf(fp,"%s%s%s%d%d",p1->sno,p1->cno,p1->cname,&p1->xuefen,&p1->biaoji);
}
p1->next =NULL;
if(fclose(fp))
{
printf("close file error!\n");
exit(0);
}
p2=(struct Course*)malloc(sizeof(struct Course));
p2=head;
while(p2!=NULL)
{
printf("2. %s %s %s %d %d\n",p2->sno,p2->cno,p2->cname,p2->xuefen,p2->biaoji);
p2=p2->next;
}
}