为什么存入txt文件什么内容也没有?

被坑的瓜 被坑的瓜 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 20

struct Student//定义一个通讯录结构体
{
char name[30];//学生姓名
char sex[10];//学生性别
int phone[20];//学生联系电话
int age[5];//学生年龄
char add[30];//学生地址
}stu[N];//定义学生的结构体变量为stu

//***********************************************
//录入信息
//***********************************************
void luru()
{
FILE *fp;
int i;
//输入学生的数据,存放在数组stu中
printf("请输入学生姓名:");
scanf("%s",stu[N].name);
printf("请输入学生性别:");
scanf("%s",stu[N].sex);
printf("请输入学生电话:");
scanf("%d",stu[N].phone);
printf("请输入学生年龄:");
scanf("%d",stu[N].age);
printf("请输入学生地址:");
scanf("%s",stu[N].add);

//把数据转存到磁盘文件中

if((fp=fopen("通讯录.txt","a+"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
for(i=0;i<N;i++)
{
if(fwrite(&stu[i],sizeof(struct Student),1,fp)!=1)
printf("file write error\n");
}
fclose(fp);
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
被坑的瓜
C语言 70,040 成员 243,237 内容