char *filename="lll.txt";
void init(){
FILE *p,*q;
p=fopen(filename,"rb");
if(p!=NULL){
fread(&count,sizeof(int),1,p);
printf("%d",count);
for(i=0;i<count;i++){
fread(&list[i],sizeof(struct maillist),1,p);
}
for(i=0;i<count;i++){
printf("%s %s",list[i].name,list[i].tel);
}
}
else{
q=fopen(filename,"wb");
fwrite(&count,sizeof(int),1,q);
printf("通讯录文件初始化成功\n");
fclose(q);
}
fclose(p);
}
void insert(){
struct maillist person;
FILE *p;
p=fopen(filename,"ab+");
if(p!=NULL){
printf("输入格式:姓名 电话\n");
scanf("%s %s",person.name,person.tel);
getchar();
fwrite(&person,sizeof(struct maillist),1,p);
printf("%s %s",person.name,person.tel);
printf("添加成功");
count++;
printf("%d",count);
}
p=fopen(filename,"rb+");
fwrite(&count,sizeof(int),1,p);
fclose(p);
}
每次读取的时候都是乱码 求指教 |
|