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_NAME_LEN 30 |
#define FACULTY_OFFICE_LEN 7 |
#define FACULTY_PHONE_LEN 15 |
#define FACULTY_EMAIL_LEN 30 |
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
***********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 COMMAND_NAME_LEN 7 |
char name[COMMAND_NAME_LEN]; |
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****************
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 |
int find_by_office(char *office) |
// REMOVE THE FOLLOWING LINE BEFORE ADDING YOUR CODE |
int find_by_phone(char *phone) |
int find_by_email(char *email) |
}
**********MAIN.C**************
int main(int argc, char *argv[]) |
// REMOVE THE FOLLOWING LINE BEFORE ADDING YOUR CODE |
(void) argc; (void) argv; |
}