双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

c链表输出

xiaohanliu xiaohanliu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想实现从文件当中把信息录入链表里然后打印出来,如何实现,那一不出错了呢?错误是:p1信息录入不到head里
#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,*p;

if((fp=fopen("sc.txt","r"))==NULL)
{
printf("open file error!\n");
exit(0);
}
p1=head=(struct Course*)malloc(sizeof(struct Course));
p1=head;
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=(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;
}
}

...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
xiaohanliu
C语言 70,039 成员 243,237 内容