Telephone Directory

Posted by Mizukage of Meron 5 on Stack Overflow See other posts from Stack Overflow or by Mizukage of Meron 5
Published on 2014-08-20T04:14:46Z Indexed on 2014/08/20 4:20 UTC
Read the original article Hit count: 156

Filed under:

I need your help. We are ask to make a telephone directory program that asks your name, address, and telephone number. If the name you entered already exists, it will display that it already exists. This is what i have so far...

#include<stdio.h>
#include<conio.h>

struct file {
 char name[25],address[25];
 double telno;
 };

char tempname[25],tempadd[25];
double tempnum;
int x;
int choice;

FILE *fp;

main()
{

struct file rec;
clrscr();

fp=fopen("TelDir.txt","a+");

while(!feof(fp))
{
    fscanf(fp,"%s %s %.0lf,&tempname,&tempadd,&tempnum);
    printf("\n%s\t\t%s\t\t\t%.0lf",tempname,tempadd,tempnum);

    printf("\nEnter Name: ");
    gets(rec.name);

        if(strcmp(rec.name,tempname)==1)
        {
            printf("\n\nALREADY EXIST!");
            printf("\n%s\t\t%s\t\t\t%.0lf",tempname,tempadd,tempnum);
            getch();
        }
        else
        {
            printf("Enter Address: ");
            scanf("%s",&rec.address);

            printf("Enter your Telephone No.: ");
            scanf("%lf",&rec.telno);

            printf("%s\t\t%s\t\t%\t\t0lf",rec.name,rec.address,rec.telno);
            fprintf(fp,"%s %s %.0lf\n",rec.name,rec.address,rec.telno);
        }
}

fclose(fp);
getch();
}

But this thing doesn't work. I don't know where the error is. Can someone help me on this? I would really appreciate if you could help me somehow.

© Stack Overflow or respective owner

Related posts about c