Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Build a command-line phonebook that allows you look up the office, phone number, and email address of people on the struct implement the find functions

Build a command-line phonebook that allows you look up the office, phone number, and email address of people on the struct

implement the find functions in commands.c to find entries in the faculty array

Useqsort() and bsearch()

Note that you will need to implement functions to compare two professor structs based on their fields

Modify main.c to:

Use argc, argv, and bsearch() to find the appropriate find command function pointer from the commands table

Use the pointer to call the appropriate find function from commands.c in order to search the faculty array for the given arguments

Print the matching record

EXAMPLE:

$ ./phonebook email Usage: phonebook $ ./phonebook email KoAndrew@university.edu Ko, Andrew CS-538 (657) 238-2998 KoAndrew@university.edu

***************FACULTY.H*************************

#define FACULTY_H
#define NUM_FACULTY 16
#define FACULTY_NAME_LEN 30
#define FACULTY_OFFICE_LEN 7
#define FACULTY_PHONE_LEN 15
#define FACULTY_EMAIL_LEN 30
struct professor {
char name[FACULTY_NAME_LEN];
char office[FACULTY_OFFICE_LEN];
char phone[FACULTY_PHONE_LEN];
char email[FACULTY_EMAIL_LEN];
};
extern struct professor faculty[NUM_FACULTY];

#endif

#ifndef FACULTY_H

***********FACULTY.C****************

#include "faculty.h"

struct professor faculty[NUM_FACULTY] = { { "Whaling, Michael", "CS-540", "(657) 269-3291", "mshafae@university.edu" }, { "Buras, Susamma", "CS-502", "(657) 269-3262", "sbarua@university.edu" }, { "Johnson, Doina", "CS-542", "(657) 269-4322", "dbein@university.edu" }, { "Chenon, Ning", "CS-546", "(657) 269-3293", "nchen@university.edu" }, { "Chon, James S.", "CS-544", "(657) 269-7347", "jchoi@university.edu" }, { "Con, Bin", "CS-417", "(657) 269-2031", "bcong@university.edu" }, { "Golfman, Mikhail", "CS-538", "(657) 269-7324", "mgofman@university.edu" }, { "Hanso, Wenlin", "CS-542", "(657) 269-7151", "whan@university.edu" }, { "Flo, Holliday", "CS-513", "(657) 269-7231", "holliday@university.edu" }, { "Inventa, Paul Salvador", "CS-534", "(657) 269-3211", "pinventado@university.edu" }, { "Joeh, Chang-Hyun", "CS-425", "(657) 269-7345", "cjo@university.edu" }, { "Pananga, Anand", "CS-538", "(657) 269-3995", "apanangadan@university.edu" }, { "Ryu, Chris", "CS-421", "(657) 269-7236", "tryu@university.edu" }, { "Tiana, Yun", "CS-538", "(657) 269-2067", "ytian@university.edu" }, { "Wan, Shaun", "CS-532", "(657) 269-7288", "xwang@university.edu" }, { "Wartman, Kevin", "CS-538", "(657) 269-2978", "kwortman@university.edu" } };

*************COMMAND.H*****************************

#define COMMANDS_H
#define NUM_COMMANDS 4
#define COMMAND_NAME_LEN 7
struct command {
char name[COMMAND_NAME_LEN];
int (*function)(char *);
}
extern struct command commands[NUM_COMMANDS];
int find_by_name(char *);
int find_by_office(char *);
int find_by_phone(char *);
int find_by_email(char *);

#endif

****************COMMAND.C****************

#include "faculty.h"
struct command commands[NUM_COMMANDS] = {
{ "email", find_by_email},
{ "name", find_by_name },
{ "office", find_by_office },
{ "phone", find_by_phone },
};
int find_by_name(char *name)
{
// REMOVE THE FOLLOWING LINE BEFORE ADDING YOUR CODE
(void) name;
// INSERT CODE HERE
return -1;
}
int find_by_office(char *office)
{
// REMOVE THE FOLLOWING LINE BEFORE ADDING YOUR CODE
(void) office;
// INSERT CODE HERE
return -1;
}
int find_by_phone(char *phone)
{
(void) phone;
// INSERT CODE HERE
return -1;
}
int find_by_email(char *email)
{
(void) email;
// INSERT CODE HERE
return -1;

}

#include "commands.h"

**********MAIN.C**************

#include
#include
#include "commands.h"
#include "faculty.h"
int main(int argc, char *argv[])
{
// REMOVE THE FOLLOWING LINE BEFORE ADDING YOUR CODE
(void) argc; (void) argv;
// INSERT CODE HERE
return EXIT_SUCCESS;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

Classify delivery styles by type.

Answered: 1 week ago