hi i'm a newbie noobie in C...anyways i'm trying to create program that can hold contact infos. of persons in short a simple phonebook...and i want to make my program same as with this:
v=Z5i07EF_Nh4YouTube - c language phone book program
well i'm trying soO hard to make it like that but i cant figure out how did the person made that..anyways i need help please someone improve my code cuz i really need it after 5 hours..
here's my code:
Code:# include <stdio.h>
# include <conio.h>
# include <string.h>
#define clrscr()
struct teledir{
long teleno ;
char name[20];
char address[20];
};
main()
{
struct teledir t;
FILE *fp;
long tno;
char sname[20],c;
int ch;
while(1)
{
clrscr();
printf("\t\t\t\tMENU\n");
printf("1. TO ADD THE RECORD IN THE FILE.\n");
printf("2. TO SEARCH THE RECORD BY NAME.\n");
printf("3. TO VIEW RECORDS.\n");
printf("ENTER YOUR CHOICE:-> ");
scanf("%d",&ch);
switch(ch)
{
case 1:
fp=fopen("telephon.txt","ab");
while (1)
{
clrscr();
printf("ENTER THE TELEPHONE NUMBER:-> ");
scanf("%ld",&t.teleno);
fflush(stdin);
printf("\nENTER THE NAME :-> ");
scanf("%s",t.name);
fflush(stdin);
printf("\nENTER THE ADDRESS :-> ");
scanf("%s",t.address);
fwrite(&t,sizeof(t),1,fp);
fflush(stdin);
printf("\n\nWISH TO CONTINUE?(Y/N) \n\n");
scanf("%c",&c);
if(c=='n' || c=='N')
break;
}
fclose(fp);
break;
case 2:
fp=fopen("telephon.txt","rb");
clrscr();
printf("ENTER THE NAME :-> ");
scanf("%s",sname);
while(fread(&t,sizeof(t),1,fp))
{
if(strcmp(sname,t.name)==0)
{
a: printf("\n\t TELEPHONE NUMBER: %ld\t NAME: %s\t ADDRESS: %s",t.teleno,t.name,t.address);
scanf("%c",&c);
if(c=='n' || c=='N')
getch();
break;
}
}
fclose(fp);
getch();
break;
default:
goto a;
break;
}
}
getch();
}