求助,运行错误,求解

敲风奏雨 2017-02-08 06:57:52
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 20
int i=0;
FILE*fp;
struct account
{int id;
char name[10];
float balance;
}newone[SIZE];

int main(){
printf("请输入账号:");
scanf("%d",&newone[i].id);
printf("账户名:");
scanf("%s",&newone[i].name);
printf("账户余额:");
newone[i].balance=0.0;
scanf("%f",&newone[i].balance);

if(fopen("date.dat","wb")==NULL){
printf("cannot open file\n");
exit(0);
}
if(fwrite(&newone[i],sizeof(struct account)+1,1,fp)!=1)printf("write file orror\n");
fclose(fp);
i++;
}
...全文
45 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
幻夢之葉 2017-02-08
  • 打赏
  • 举报
回复
if(fopen("date.dat","wb")==NULL) 修改为 if ((fp = fopen("date.dat", "wb")) == NULL) 你fp没有赋值就使用了(NULL)

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧