Code:#include <stdio.h>
#include <stdlib.h>
FILE* fin;
FILE* fout;
typedef struct KnightsMartProduct {
int itemNum;
char itemName[21];
double unitPrice;
int stockQty;
int restockQty;
struct KnightsMartProduct *next;
} KMProduct;
typedef struct KnightsMartRestockProduct {
int itemNum;
struct KnightsMartRestockProduct *next;
} KMRestockProduct;
typedef struct KnightsMartSale {
char firstName[21];
char lastName[21];
int numItemsonList; // # of items on shopping list
int *itemsPurchased; // array of item numbers
struct KnightsMartSale *next;
} KMSale;
//KMProduct ordered linked list of products
struct KnightsMartProduct* insertAdd(struct KnightsMartProduct *Products, FILE* fin,int NewItemNum,char NewItemName[],int itemPrice,int stockQty,int restockQty);
struct KnightsMartRestockProduct* delete(struct KnightsMartProduct *Products,struct KnightsMartRestockProduct *RestockList, FILE* fin, int ItemNum);
struct KnightsMartProduct* insertAdd(struct KnightsMartProduct *Products, FILE* fin,int NewItemNum,char NewItemName[],int itemPrice,int stockQty,int restockQty)
{
KMProduct *pNew = (KMProduct *) malloc(sizeof(KMProduct));
KMProduct *help_ptr = Products;
pNew->itemNum = NewItemNum;
//pNew->itemName = NewItemName;
pNew->unitPrice = itemPrice;
pNew->stockQty = stockQty;
pNew->restockQty = restockQty;
fscanf (" %d ", &pNew->itemNum);
if ( help_ptr == NULL || help_ptr->itemNum > NewItemNum) {
pNew->next = Products;
Products = pNew;
return Products;
}
while(help_ptr->next != NULL && help_ptr->next->itemNum < NewItemNum)
help_ptr = help_ptr->next;
pNew->next = help_ptr->next;
help_ptr->next = pNew;
return Products;
}
//printf("\n");
struct KnightsMartRestockProduct* delete(struct KnightsMartProduct *Products,struct KnightsMartRestockProduct* RestockList, FILE* fin,int ItemNum){
struct KnightsMartRestockProduct *help_ptr, *node2delete;
help_ptr = RestockList;
if (help_ptr != NULL){
if (help_ptr->itemNum == ItemNum ){
RestockList = help_ptr->next;
free(help_ptr);
return RestockList;
}
while (help_ptr->next != NULL ){
if (help_ptr->next->itemNum == ItemNum){
node2delete = help_ptr->next;
help_ptr->next = help_ptr->next->next;
free(node2delete);
return RestockList;
}
help_ptr = help_ptr->next;
}
}
return RestockList;
}
struct KnightsMartSale* Sale(struct KnightsMartSale *cSale){//, FILE * fin){//, char firstName, char lastName, int numItemsonList
KMSale *pNew = (KMSale *) malloc(sizeof(KMSale));
&pNew->itemNum = itemNum;
KMSale *help_ptr = cSale;
fscanf(fin, "%s %s %d", &pNew->firstName, &pNew->lastName, &pNew->itemNum);
}
//KMSales
//Printf ("%d %s %lf);
int main(int argc, char *argv[])
{
KMProduct *Products = NULL;
KMRestockProduct *RestockList = NULL;
KMSale *cSale = NULL;
int NewItemNum;
char NewItemName[21];
int itemPrice;
int stockQty;
int restockQty;
char command[20];
int itemNum;
FILE *fin;
fin = fopen("KnightsMart.txt", "r");
fscanf (fin, "%s", &command);
delete(Products,RestockList,fin,itemNum);
if(strcmp(command, "ADDITEM")== 0){
fscanf(fin, " %d %s %lf %d %d", &Products->itemNum, &Products->itemName, &Products->unitPrice, &Products->stockQty, &Products->restockQty);
Products = insertAdd (Products, fin, NewItemNum, NewItemName, itemPrice, stockQty, restockQty);
//fscanf(fin, "%s %s %d", &pNew->firstName, &pNew->lastName, &pNew->itemNum);
//KMSale* pnew(KMSale *)malloc(sizeof(KMSale)) ;
//pNew-> =
Sale(cSale);
//if(strcmp(command, "RESTOCK")== 0){
// fscanf(fin, " %d %d %d", &Products->itemNum, &Products->stockQty, &Products->restockQty);
//if(strcmp(command, "CUSTOMER")== 0){
}
//printf ("\t| Item %6d | %-20s |
system("PAUSE");
return 0;
}