zycxiazai123 2014-07-22 14:52 采纳率: 0%
浏览 1825

C语言运行总是出问题。。。。

#include
#include
#include
#include
//将一块内存数据写入文件中 使用的函数为:fwrite;
#define NUM 2
typedef struct
{
char name[20];
int age;
char email[50];
}person; //定义结构体 结构体名为person;

void getinfor(person* pinfor)
{
printf("input name: ");
gets(pinfor->name);
printf("input age: ");
scanf("%d",&pinfor->age);
//getchar();
//printf("input email ");
//gets("pinfor->email");
}

void main(void)
{

person people[NUM]; //声明结构体数组,结构体名称为 person 数组名为 people;
//声明文件,要写入的文件名;
char filename[50];
printf("please input the file name that you want to save date : \n");
gets(filename);
FILE* fpo = NULL;
fpo = fopen(filename,"wt");
if (fpo == NULL)
{
printf("the file open fail,check again please!\n");
exit(0);
}
else
printf("the file open success!\n");
for (int i=0;i<NUM;i++)
{
getinfor(&people[i]);
if (fwrite(&people[i],sizeof(person),1,fpo) == 0)
{
printf("fwrite in fail\n");
exit(0);
}
else
printf("write in success!\n");
}
fclose(fpo);
printf("The file has been closed\n");
}

各位大牛帮帮忙呀 谢谢大家~!

  • 写回答

1条回答

  • 小邓在路上 2014-07-23 01:10
    关注

    问题很简单,我只说一句话,不懂就说明你对内存理解不行:
    在一个被调函数结束的时候不可以返回栈空间或者是局部动态内存。
    不理解再问吧!

    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题