回复 19楼 voidx
struct connection *open(FILE *ps1,struct connection *head,struct connection *p) //读取历史记录
{
struct connection *s;
p=head;
while(fgetc(ps1)!=EOF)
{
s=(struct connection*)malloc(sizeof(struct connection));
p->next=s;
fscanf(ps1,"%d%s%s%s%s",&p->number,&p->name,&p->adress,&p->tphone,&p->qq);
p=s;
}
p->next=NULL;
return head;
}
void os(FILE *ps,FILE *ps1,struct connection *head,struct connection *p) //写进文件里
{
rewind(ps);
rewind(ps1);
p=head->next;
fprintf(ps,"\t****************************************************\n");
fprintf(ps,"编号\t\t名字\t\t地址\t\t电话或联系方式\t\tQQ号\n");
while(p!=NULL)
{
fprintf(ps1,"%d %s %s %s %s ",p->number,p->name,p->adress,p->tphone,p->qq);
fprintf(ps,"%d %18s %18s %18s %18s\n",p->number,p->name,p->adress,p->tphone,p->qq);
p=p->next;
}
fprintf(ps,"******************************************************\n");
printf("保存成功!\n");
}
void display(struct connection *head,struct connection *p) //显示通讯录
{
p=head->next;
printf("\t****************************************************\n");
printf("编号\t\t名字\t\t地址\t\t电话或联系方式\t\tQQ号\n");
while(p!=NULL)
{
printf("%d %18s %18s %18s %18s\n",p->number,p->name,p->adress,p->tphone,p->qq);
p=p->next;
}
if(p==NULL)
{
printf("待添加..................\n");
}
printf("******************************************************\n");
}
void main()
{
FILE *ps,*ps1;
char c;
if((ps=fopen("通讯录.txt","w+"))==NULL)
{
printf("error");
exit(0);
}
printf("是否要导入以前的历史记录: y/n \n");
fflush(stdin);
c=getchar();
if(c=='y')
{
printf("成功了!\n");
if((ps1=fopen("通讯录历史.test","rb+"))==NULL)
{
printf("没有记录!\n");
exit(0);
}
int m;
struct connection *p,*head,*q;
head=(struct connection*)malloc(sizeof(struct connection));
head=open(ps1,head,p);
p=head;
}
不用看后面,看前面的子函数,即使这样实现的存储,使用rb的格式,求解