做文件输入输出的时候,用的是结构体链表,放入的链表只有两个一个是头,
另一个是有内容的(头无内容)。但是每次读出的时候总会多出一个节点,
结构体 和 读入 读出 代码如下
typedef struct vip //定义VIP用户的结构体
{
char card[19];
char name[11];
char tel[14];
int time;
char date[13];
char key[11];
struct vip *next;
}vip;
typedef struct cus //定义登陆用户的结构体(包括临时和VIP)
{
char card[19];
int lie; //位置;
char date[13]; //上机日期
time_t upt; //上机时间
time_t downt; //下机时间
int in; //押金
int realin; //实际收入
int flag; //1 激活状态 0 未激活(下机)状态
int identify; //1 VIP 用户 2 临时用户
char tel[14];
struct cus *next;
}cus;
void load(vip *head1,cus *head2,int longth) //装载VIP 和 临时登陆 的 记录
{
FILE *fp1,*fp2;
vip *p1,*tail1 = head1;
cus *p2,*tail2 = head2;
fp1 = fopen("vip.bin","rb")
if((fp2 = fopen("day.bin","rb")) == NULL)
{
return ;
}
while(!feof(fp1))
{
p1 = (vip *)malloc(sizeof(vip)*1);
fread(p1,sizeof(vip),1,fp1);
tail1 ->next = p1;
tail1 = p1;
tail1 ->next = NULL;
// longth ++;
printf("1");
}
while(!feof(fp2))
{
p2 = (cus *)malloc(sizeof(cus)*1);
fread(p2,sizeof(cus),1,fp2);
tail2 ->next = p2;
tail2 = p2;
tail2 ->next = NULL;
}
close(fp1);
close(fp2);
}
void a(vip *head1,cus *head2) //信息保存
{
FILE *fp1,*fp2;
vip *p1 = head1 ->next;
cus *p2 = head2 ->next;
fp1 = fopen("vip.bin","wb");
fp2 = fopen("day.bin","wb");
while(p1 != NULL)
{
fwrite(p1,sizeof(vip),1,fp1);
p1 = p1 ->next;
}
while(p2 != NULL)
{
fwrite(p2,sizeof(cus),1,fp2);
p2 = p2 ->next;
}
close(fp1);
close(fp2);
}
当我运行程序时,(保存的时候 只有两个 节点,并且尾next为空),保存两个节点,第二次读取的时候却有三个节点,不知道问题出在了哪里。求大神帮忙看看!!!!!