Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey i apologize if this question is a little long. I would love any help I can g

ID: 3912615 • Letter: H

Question

Hey i apologize if this question is a little long. I would love any help I can get to complete this. It has to be in C and would appreciate anyone who can solve this so I can learn how to tackle this problem.

In this project, you will be making a program to maintain a database of items found in a convenience store. Each item has a name (assume a maximum of 50 characters) and price associated with it. Your program must use a dynamically allocated linked list to store the item information. Three base files (Stems.h, items.c and, stoze.c) are provided to you to start with, study them and complete this project by adding your code to these base files. itens.h: This file contains definitions and prototypes of functions that are defined in items.c. The structure tem is also defined to store information about a country. You need to have appropriate members for this structure. items.c:This file contains the function definitions that you need to complete. There are four functions, append item, search item, print items, and clear_tems that you need to complete. In each of these function, you should have the following functionality append item: Ask the user for name of the item. Add the item to the end of the linked list if it doesn't already exist. If the item already exists, do not add anything to the list. This function returns the list. If the list is empty. you should return the pointer to the newly created item, otherwise return the list that was passed into the function. search tem: Ask the user for name of an item and search the item with the given name in the linked list. Punction should print out the name and price of the item if it exists. If the item doesn't exist, simply print that the item was not found. print Stems: Print out all the items in the linked list. Each item with its price in printed in a new line clear stems: Clear all the items in the linked list. All dynamically allocated nodes must (individually) be freed store.c: This file has the main function. You can see a pointer variable to item structure which should point to the first node in the linked list. You do not need to modify this file IMPORTANT Do not modify the lines (source code) that are provided in the base files, only add to the files You do not need to modify store.c at all, just complete item structure in items.h and the functions append tem, seareh item, print items, and clear items in items. c. 1. 2.

Explanation / Answer

struct item{

    char name[50];
    float price;
    struct item *next;
};

struct item *append(struct item *item_list){

   char name[50];
   float price;
   struct item *s;
   printf("Enter item name:");
   scanf("%s",name);
   printf("Enter price:");
   scanf("%f",&price);
   struct item *p;
   int found = 0;
   p = item_list;
   struct item *q = (struct item *)malloc(sizeof(struct item));
   q->next = NULL;
   strcpy(q->name, name);
   q->price = price;
   if (p == NULL){
       item_list = q;
      
   }
   else {
      
       while(p != NULL){
            if (strcmp(name,p->name) == 0){
               found = 1;
               break;
            }
            s = p;
            p = p->next;
       }
       if (found == 0){
          s->next = q;
       }
       else {
          printf("Item already present ");   
       }
   }
   return item_list;
}


void search_item(struct item *item_list){

   char name[50];
   printf("Enter item name:");
   scanf("%s",name);
   struct item *p;
   int found = 0;
   p = item_list;
   if (p == NULL){
       printf("List is empty ");
   }
   else {
       while(p != NULL){
            if (strcmp(name,p->name) == 0){
               found = 1;
               printf("%-20s %20s %5s %10s ","Price of",p->name,"is",p->price);
               break;
            }
            p = p->next;
       }
       if (found == 0){
          printf("Item not found ");
       }
   }
}

void print_items(struct item *item_list){

   struct item *p = item_list;
   if (p == NULL){
       printf("List is empty ");
   }
   else {
       while(p != NULL){
            printf("%-20s %20s %5s %10s ","Price of",p->name,"is",p->price);
            p = p->next;
       }
   }
}

void clear_items(struct item *item_list){

   struct item *p = item_list;
   struct item *q;
   if (p == NULL){
       printf("List is empty ");
   }
   else {
       while(p != NULL){
            q = p;
            p = p->next;
            free(q);
       }
   }
}