问题和代码不完整
猜想精简一下
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
#include <stdio.h>
struct records
{
char consumer[4];
char classification[6];
} Message[100];
int Fetch()
{
int i,a=0;
FILE *fp;
if((fp=fopen("jilu.txt","rb"))==NULL)
{
printf("无法打开文件!");
return -1;
}
for (a=0; fread(&Message[a],sizeof(struct records),1,fp)==1; ++a);
fclose(fp);
for(i=0; i<a; i++)
printf("%-4s
%-6s\n",Message[i].consumer,Message[i].classification);
return a;
}
int main(void)
{
struct records msg[3] = {"aaa","AAA",
"bbb","BBB",
"ccc","CCC"
};
FILE *fp;
if((fp=fopen("jilu.txt","wb"))==NULL)
return -1;
fwrite(msg, sizeof(struct records), 3, fp);
fclose(fp);
printf("%d\n",Fetch());
return 0;
}