file handling

my program is a telephone directory, it is a list of content details includes persons name and his/her telephone number. My program should be able to add, edit, display and search a contact.

so here is my concern and i hope i got some help thank you in advance. I've already done the codes but there is a little problem. when the user add an new file it's working, she/he can put his/her name and telephone number but when he/she want to see or display the data the output is kinnda messy he/she can see the information but the telephone number appears in a special characters like hearts,smiles,mathematical sign, and also the search one when the user search a name the one she/he's been searching have already a name and a telephone number but when the output is not correct the name is exact but the telephone number is not correct.

here is my codes for the searching and editing.
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();
}
Hi myme,

I wouldn't go with type integer for telephone numbers. You'll be better off using strings or char arrays for that. Reason: int has a small valid range, can't handle extra chars linke 0101-456778 or /+ etc...
what should i do?
Topic archived. No new replies allowed.