tes: phone.book.c is pr file phone.book.c, a to understand all the details, but
ID: 3703533 • Letter: T
Question
tes: phone.book.c is pr file phone.book.c, a to understand all the details, but do not change anything in this code. Note that the first function works with a pointer to the structure pb, where in the second function the structure itself is passed to the function along with a name (character array) to be found. There are no double spaces, but make sure you have the correct line feeds when printing the names. For the printed information of the searched contact, there is one line feed before and one after each contactExplanation / Answer
// libpb.h
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#ifdef __linux__
#define CLEAR_SCREEN system("clear")
#elif _WIN32
#define CLEAR_SCREEN system("cls")
#endif
typedef struct personal_info
{
char first[25];
char last[25];
char phone[15];
}personal_info;
typedef struct phone_book
{
struct personal_info[20];
int num_people;
} phone_book ;
/* Root Node */
extern phone_book * pb ;
/* basic verbs */
extern void add_person (struct phone_book *pb,struct personal_info person ) ;
extern void search_pb(struct phone_book pb,char find_name[] ) ;
...............................................................................................................................................................
//phone_book.c
include "libpb.h"
#include<stdio.h>
#include<string.h>
void add_person(struct phone_book *pb,struct personal_info person)
{
pb->num_people++;
pb->personal_info[pb->num_people]=person;
}
void search_pb(struct phone_book pb,char find_name[] )
{
int i=0;
for(i=0;i<20;i++)
{
if(!strcmp(pb.personal_info[i].first,find_name))
printf("contact found in phone_book");
else
printf("contact not found in phone_book");
}
}
int main()
{
struct person_info person;
struct phone_book*pb;
char first [25]
char last[25];
char phone[15];
printf (" 1 . %-12s " , "Add Contact") ;
printf (" 2 . %-12s " , "Search")
ch = getchar() ;
input_flush() ;
CLEAR_SCREEN ;
switch ( ch )
{
case '1':
printf("Enter the first name")
scanf("%s",person.first);
printf("Enter the last name")
scanf("%s",person.lst);
printf("Enter the phone number")
scanf("%s",person.phone);
add_person(pb,person);
break ;
case '2':
printf("Enter the first name to be search")
scanf("%s",first);
search_pb(pb,first);
break ;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.