c语言将数据写不入文件,求大神看看为什么不能将数据写入文件

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

void baocunXS(struct stu *head);

struct stu *creat();

struct stu

{

int chengji;

int xuhao;

struct stu *next;//结构体指针自引用

};

void ps(struct stu *head)

{

struct stu *p;

p=head;

if(p!=NULL)

{

do

{

printf("学号=%d 成绩=%d\n",p->xuhao,p->chengji);

p=p->next;

}while(p!=NULL);

}

}

void baocunXS(struct stu *head)

{

FILE *bcxs;

struct stu *p;

char x[30]={0};

char y[30]={0};

char z[30]={0};

p = head;

if ((bcxs = fopen("bcxs.txt", "a+")) = NULL)

{

printf("文件打开或创建失败!");

}

else

{

if (p != NULL)

{

do

{

fwrite(bcxs,sizeof(struct stu),1,bcxs);

p = p->next;

} while (p != NULL);

}

}

fclose(bcxs);

}

struct stu *creat()

{

struct stu *head,*p1,*p2;

p2=p1=(struct stu *)malloc(sizeof(struct stu));

printf("请输入学生信息\n");

printf("请输入学号\n");

scanf("%d",&p1->xuhao);

printf("请输入成绩\n");

scanf("%d",&p1->chengji);

head=NULL;

int n=0;

while(0!=p1->xuhao)

{

n++;

if(n==1)

{

head=p1;

}

else

{

p2->next=p1;

}

p2=p1;

p1=(struct stu *)malloc(sizeof(struct stu));

printf("请输入学生信息\n");

printf("请输入学号\n");

scanf("%d",&p1->xuhao);

printf("请输入成绩");

scanf("%d",&p1->chengji);

}

p2->next=NULL;

return head;

}

main()

{

struct stu *s;

s=creat();

ps(s);

baocunXS(s);

getch();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值