文件读写完后fclose()就内存溢出

lonelyandrew lonelyandrew 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
linux环境下编译的
#include <stdlib.h>
#include <malloc.h>
typedef struct
{
char *CardCode;
char *Name;
char *Contact;
char *Password;
char AccountType;
double MoneyCount;
}*AccountRecord, AccountInfo;

int AccountInfoWrite(AccountInfo Record)
{
FILE *fp;
char *FileName="12345678.Bq";
fp=fopen(FileName, "w");
if (fp==NULL)
{
printf("文件已新建! \n");
return 1;
}
if (fwrite(&Record, sizeof(AccountInfo), 1, fp) == 1)
{
printf("账户信息写入成功! \n");
fclose(fp);
return 0;
}
else
{
printf("账户信息写入失败! \n");
return 1;
}
}

void read()
{
AccountInfo buffer;
FILE *fp;
fp=fopen("12345678.Bq", "rb");
if (fp==NULL)
{
printf("open file error!\n");
return;
}
fread(&buffer, sizeof(AccountInfo), 1, fp);
fclose(fp);
printf("%s \n", buffer.Name);
}

int main()
{
AccountRecord a = (AccountRecord)malloc(sizeof(AccountRecord));
a->Name = "aassasasa";
a->CardCode = "12345678";
a->Contact = "110";
a->Password = "112233";
a->AccountType = 'a';
a->MoneyCount = 111.00;
AccountInfoWrite(*a);
read();
return 0;
}

...全文

相关推荐

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