/********************************************************* * * main.c * * Main program for the phone number program. The main * program is responsible for all interactions with the * user. It first determines the file that the phone * book is stored on and then calls read_phone_file to * read the phone book. The program then asks the user * for the names of people and prints their phone numbers. * The get_phone_number procedure us used to lookup a * phone number given a person's name. The phone book * data structure is maintained by the routines in the * phone.c file. * *******************************************************/ #include #include #include "phone.h" int main (int argc, char** argv) { FILE* fid; char name[NAMELENGTH]; char* phone; if (argc != 2) { printf ("usage: phone phone_file\n"); return (1); } fid = fopen (argv[1], "r"); if (fid == NULL) { printf("unable to open phone file: %s\n", argv[1]); return (2); } read_phone_file (fid); while (TRUE) { printf("name: "); scanf ("%20s", &name[0]); if (strcmp (name, "exit") == 0) break; phone = get_phone_number(name); if (phone == NULL) { printf("sorry, no number for %s\n", name); } else { printf("the phone number for %s is %s\n", name, phone); } } return (0); }