1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
//edit
void edit(FILE *fp)
{
tlPhone user;
int count = 0;
char name[15];
fp=fopen("telephone.txt","r+");
fread(&user,sizeof(tlPhone),1,fp);
printf("Old Person Name:");
scanf("%s",name);
while(!feof(fp))
{
count++;
if(strcmp(name,user.usrname)==0)
{
printf("New Person Name: ");fflush(stdin);
gets(user.usrname);
printf("New Person Tel. No: ");
scanf("%d",&user.usrno);
fseek(fp,(count-1)*sizeof(tlPhone),SEEK_SET);
fwrite(&user,sizeof(tlPhone),1,fp);
break;
}
fread(&user,sizeof(tlPhone),1,fp);
}
getch();
fclose(fp);
}
//seacrh
void search(FILE *fp)
{
tlPhone user;
char name[20];
int count=0;
fp=fopen("telephone.txt","r");
printf("\nName (You want to see): ");
scanf("%s",&name);
while(!feof(fp))
{
fread(&user,sizeof(tlPhone),1,fp);
if(strcmp(name,user.usrname)==0)
{
printf("\nNames\t\tTel.No\n");
printf("\n %s\t\t ",user.usrname);
printf("%d",user.usrno);break;
}
}
if(count!=0)
printf("\n\n\nData not found!");
fclose(fp);
getch();
}
| |