struct store //门面信息
{ char address[30]; //门面地址
int staffnum; //员工数量
int id; //店面编号
struct store *link; };
typedef struct store Store;
void LoadChain_store()
{
Store *p; FILE *fp;
if((fp=fopen("store.dat","rb"))==NULL)
{ printf("打开store文件出错"); Sleep(3000); exit(0); }
p=(Store *)malloc(sizeof(struct store));
p->link=NULL;
store_first=p;
while(!feof(fp))
{
p->link=(Store *)malloc(sizeof(struct store));
p=p->link; fread(p,sizeof(struct store),1,fp);
p->link=NULL;
}
fclose(fp);
}
void SaveChain_store()
{
FILE *fp;
Store *p;
if((fp=fopen("store.dat","wb+"))==NULL) { printf("打开store文件出错"); Sleep(3000); exit(0); }
p=store_first->link;
while(p->link!=NULL)
{ p=p->link; fwrite(p,sizeof(struct store),1,fp); }
}
先看看这边有没有什么问题,楼下贴输入和输出代码
我的问题是我存进去了店面编号为1 2 3 4 5 6的6个数据
存储进去后输出变成了2 3 4 5 6 乱码 也就是编号为1的数据失踪了 结尾处多了一组乱码数据,然后每保存一次再运行 第一个数据都会丢失,最后都会多出一组乱码数据 到最后变成全为乱码
{ char address[30]; //门面地址
int staffnum; //员工数量
int id; //店面编号
struct store *link; };
typedef struct store Store;
void LoadChain_store()
{
Store *p; FILE *fp;
if((fp=fopen("store.dat","rb"))==NULL)
{ printf("打开store文件出错"); Sleep(3000); exit(0); }
p=(Store *)malloc(sizeof(struct store));
p->link=NULL;
store_first=p;
while(!feof(fp))
{
p->link=(Store *)malloc(sizeof(struct store));
p=p->link; fread(p,sizeof(struct store),1,fp);
p->link=NULL;
}
fclose(fp);
}
void SaveChain_store()
{
FILE *fp;
Store *p;
if((fp=fopen("store.dat","wb+"))==NULL) { printf("打开store文件出错"); Sleep(3000); exit(0); }
p=store_first->link;
while(p->link!=NULL)
{ p=p->link; fwrite(p,sizeof(struct store),1,fp); }
}
先看看这边有没有什么问题,楼下贴输入和输出代码
我的问题是我存进去了店面编号为1 2 3 4 5 6的6个数据
存储进去后输出变成了2 3 4 5 6 乱码 也就是编号为1的数据失踪了 结尾处多了一组乱码数据,然后每保存一次再运行 第一个数据都会丢失,最后都会多出一组乱码数据 到最后变成全为乱码
