Question: #include #include #include #include //Function declarations void searchRecord(); void addRecord(); void printAll(); //converts a string to lower case. char *mystrlwr(char *str) { unsigned char *p

#include #include #include #include  //Function declarations void searchRecord(); void addRecord(); void printAll(); //converts a string to lower case. char *mystrlwr(char *str) { unsigned char *p = (unsigned char *)str; while (*p) { *p = tolower((unsigned char)*p); p++; } return str; } FILE *directory; //file pointer int main() { char choice; while(1) { printf(" Enter \t'a' for adding new record. "); printf("\t'p' for printing all records. "); printf("\t's' for searching records. "); printf("\tAny other key to exit. "); printf("\tWaiting for your input: "); scanf(" %c", &choice); if (choice == 'a') addRecord(); else if (choice == 'p') printAll(); else if (choice == 's') searchRecord(); else break; } return 0; } //Function to print all records. void printAll() { char name[50]; char phone[20]; directory = fopen("directory.txt", "r"); system("clear"); // use system("cls"); on Windows printf("Name\t\tPhone number "); while(1) { fscanf(directory, "%s %s", name, phone); if (feof(directory)) break; printf("%s\t\t%s ", name, phone); } //close file so that it can be opened in //any other mode if needed. fclose(directory); } //Function to add new records. void addRecord() { char name[50]; char phone[20]; directory = fopen("directory.txt", "a"); system("clear"); // use system("cls"); on Windows printf("Enter name: "); scanf("%s", name); printf("Enter phone number: "); scanf("%s", phone); fprintf(directory, "%s %s ", name, phone); printf("Record added successfully. "); //close the file so that it can be opened in //reading mode if necessary. fclose(directory); } //Function to search a record. void searchRecord() { char searchstring[50]; char name[50]; char phone[20]; directory = fopen("directory.txt", "r"); system("clear"); // use system("cls"); on Windows printf("Enter name to search: "); scanf("%s", searchstring); printf("Name\t\tPhone number "); while(1) { fscanf(directory, "%s %s", name, phone); if (feof(directory)) break; //print record only if it matches the user input //if (strcmp(str, name)==0) char *ret = strstr(mystrlwr(name), mystrlwr(searchstring)); if (ret != NULL) printf("%s\t\t%s ", name, phone); } //close the file fclose(directory); } 

this is C in code blocks. #include #include #include #include //Function declarations void searchRecord(); void addRecord(); void

Make the following changes in the program. 1. Modify the addRecord() function so that it asks for two more fields 'last name' and email address' in addition to first name' and 'phone number, and stores them in the file. The new file format should look like this: John Green 662-622-1234 wick@live.com Frank Davis 662-722-4215 frankd@gmail.com George Davis 662-769-1000 george@gmail.com Modify searchRecord() function so that it compares the user input name with both first and last names in the file, and display records when either first or last name matches with the user input. 2. Example: If user enters 'Davis' as search string, complete records of Frank Davis and George Davis should be printed. Modify printAll() function so that it prints all four fields i.e., first name, last name, phone number, and email address. 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!