Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Is the question implemented correctly in the code if not please correct(modify it). Give the entire header file with the new function prototype. Give the

image text in transcribed

Is the question implemented correctly in the code if not please correct(modify it).

Give the entire header file with the new function prototype. Give the entire edited dogs.c file and the entire edited records.c file. Its just a matter of copy pated and little bit of editing.

Change the codes with relation with the other source and header files so that i can easity compile without changing anything. PLease follow the instruction carefully.

//Dogs.h #ifndef dog_h #define dog_h #define NAME_LEN 30 struct dog{ int number; char dog_name[NAME_LEN+1]; char owner_last_name[NAME_LEN+1]; char breed[NAME_LEN+1]; struct dog *next; }; /*function prototypes*/ struct dog *append(struct dog *list); void search(struct dog *list); void print(struct dog *list); void clear(struct dog *list); struct dog* delete_from_list(struct dog *list); int read_line(char str[], int n); #endif

/********************************************************************/

#include #include //#include "Readline.c" //#include #include"dogs.h" struct dog *append(struct dog *list){ struct dog *cur, *new_node; new_node = malloc(sizeof(struct dog)); if (new_node == NULL) { printf("Database is full; can't add more dogs. "); return list; } printf("Enter dog's patient number: "); scanf("%d", &new_node->number); for (cur = list;cur != NULL;cur = cur->next) if (cur != NULL && new_node->number == cur->number) { printf("Patient already exists. "); free(new_node); return list; } printf("Enter dog's name: "); read_line(new_node->dog_name, NAME_LEN); printf("Enter dog's breed: "); read_line(new_node->breed, NAME_LEN); printf("Enter owner's last name: "); read_line(new_node->owner_last_name, NAME_LEN); if(list == NULL) { list = new_node; return list; } else{ for(cur = list; cur->next!= NULL; cur = cur->next); cur->next = new_node; new_node->next = NULL; return list; } } /*********************************************************** * search: Prompts the user to enter a dog's name, then * * looks up dog(s) by name in the list. Prints the all the * * informaiton of the dogs with the name if found. * * Otherwise, prints a message. * * ********************************************************/ void search (struct dog *list) { char search_name[NAME_LEN+1]; struct dog *p; int found =0; printf("Enter dog's name: "); read_line(search_name, NAME_LEN); for(p=list; p != NULL; p = p->next) { if(strcmp(search_name, p->dog_name)==0){ found = 1; printf("%d\t", p->number); printf("%s\t", p->dog_name); printf("%s\t", p->breed); printf("%s ", p->owner_last_name); } } if(!found) printf("dog not found. "); } /************************************************************* * delete_from_list: Prompts the user to enter a dog's patient number, then looks up dog(s) by patient number in the list. delete the particular dog informaiton if found. * * Otherwise, prints a message. * * ********************************************************/ struct dog* delete_from_list(struct dog *list) { int pnumber; struct dog *p=list->next,*temp=list; int found =0; printf("Enter dog's patient number: "); scanf("%d",&pnumber); if(list->number==pnumber) { found=1; struct dog *pp=list; printf(" Details of deleted Dog: "); printf("%d\t", pp->number); printf("%s\t", pp->dog_name); printf("%s\t", pp->breed); printf("%s ", pp->owner_last_name); list=list->next; free(pp); } else{ while(p != NULL) { if(pnumber==p->number){ found = 1; printf(" Details of deleted Dog: "); printf("%d\t", p->number); printf("%s\t", p->dog_name); printf("%s\t", p->breed); printf("%s ", p->owner_last_name); struct dog *ss=p; temp->next=p->next; free(ss); break; } temp=p; p=p->next; } } if(!found) printf("dog's patient number not found in list. "); return list; } /************************************************************ * print: Prints a listing of all dogs in the list, showing * * the dog's patient number, name, breed, and owner's last * * name. * * *********************************************************/ void print(struct dog *list){ struct dog *p; printf("Dog Number\tDog Name\t" "Dog Breed\tOwner Last Name "); for (p = list; p != NULL; p = p->next) printf("%d\t\t%s\t\t%s\t\t%s ", p->number, p->dog_name,p->breed, p->owner_last_name); } /*************************************************************** * clear: Clears the entire linked list. It begins at the head * * of the list and frees memory allocated for each node of the * * linked list. * * ************************************************************/ void clear(struct dog *list) { struct dog *p; while(list!=NULL) { p = list; list = list->next; if(p!=NULL) free(p); } }

/********************************************************************/

//Readline.h #ifndef read_lineh #define read_lineh #define NAME_LEN 30 int read_line(char str[], int n); #endif

/********************************************************************/

//Readline.c: #include //#include //#include //#include #include"readline.h" int read_line(char str[], int n) { int ch, i = 0; while (isspace(ch = getchar())) ; str[i++] = ch; while ((ch = getchar()) != ' ') { if (i

/********************************************************************/

//Records.c #include //#include //#include //#include #include "Readline.c" #include "dogs.c" int main(void) { char code; struct dog *dog_list = NULL; printf("Operation Code: a for appending to the list, s for finding a dog" ", d for deleting a dog from list, p for printing the list; q for quit. "); for (;;) { printf("Enter operation code: "); scanf(" %c", &code); while (getchar() != ' ') /* skips to end of line */ ; switch (code) { case 'a': dog_list = append(dog_list); break; case 's': search(dog_list); break; case 'p': print(dog_list); break; case 'd': dog_list =delete_from_list(dog_list); break; case 'q': clear(dog_list); return 0; default: printf("Illegal code "); } printf(" "); } }

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 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions