|
|
|
@ -1,56 +0,0 @@
|
|
|
|
|
void update()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int i,j,count=0;
|
|
|
|
|
char name[15];
|
|
|
|
|
if((fp=fopen("data.txt","r+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("can not open");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(!feof(fp)){
|
|
|
|
|
printf("%d",count);
|
|
|
|
|
if(fread(&addrinfo[count],LEN,1,fp)==1)
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
if(count==0)
|
|
|
|
|
{
|
|
|
|
|
printf("no record\n");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
display();
|
|
|
|
|
printf("please input the name of the contact which you want to update\n");
|
|
|
|
|
printf("update name:");
|
|
|
|
|
scanf("%s",&name);
|
|
|
|
|
for(i=0;i<count;i++)
|
|
|
|
|
{ if(strcmp(name,addrinfo[i].name)==0)
|
|
|
|
|
{printf("find the contact!you can update!\n");
|
|
|
|
|
printf("name:");
|
|
|
|
|
scanf("%s",&addrinfo[i].name);
|
|
|
|
|
printf("occuption:");
|
|
|
|
|
scanf("%s",&addrinfo[i].occu);
|
|
|
|
|
printf("telephone:");
|
|
|
|
|
scanf("%s",&addrinfo[i].tel);
|
|
|
|
|
printf("email:");
|
|
|
|
|
scanf("%s",&addrinfo[i].email);
|
|
|
|
|
printf("address:");
|
|
|
|
|
scanf("%s",&addrinfo[i].address);
|
|
|
|
|
printf("update successful");//信息在数组中进行修改,需将信息写回磁盘中
|
|
|
|
|
if((fp=fopen("data.txt","wb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("can not open\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for(j=0;j<count;j++)
|
|
|
|
|
if(fwrite(&addrinfo[j],LEN,1,fp)!=1)
|
|
|
|
|
{
|
|
|
|
|
printf("can not save!");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}printf("not find contact");//若未找到联系人信息
|
|
|
|
|
}
|
|
|
|
|
|