Monday, April 5, 2021

17.8. A file contains some persons name and telephone numbers. Write a program perform the following task: i) Read telephone number and display name. ii) Read name and display telephone number.

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

#include<string.h>

struct tnt

{

char name[20];

long phone:

};

void main()

{

int i,n;

long p;

char na [20];

struct tnt a[100]

FILE *fp;

clrscr ():

fp=fopen ("J099.in", "r");

n=0;

while (fscanf (fp, "%s%ld", a[n].name, &a [n].phone) !=EOF )

n++;

printf("Telephone number: "); i

scanf (“%ld,&p);

for (i=0; 1<n; i++)

if(a[i].phone==p)

print("%s", a[i]. nane);

printf("\name: ");

scanf ("%s", &a);

for (i-0; 1<n; i++)

if (strcmp(a[1] .name, na)==0)

printf("%ld", a[i].phone);

getch ();

}

No comments:

Post a Comment