added duplicate detection
This commit is contained in:
parent
1f5d50221a
commit
0a0d94ab13
BIN
vendorInfo
BIN
vendorInfo
Binary file not shown.
28
vendorInfo.c
28
vendorInfo.c
|
@ -40,7 +40,6 @@ struct purchase_r
|
|||
/* FUNCTION DECLARATION */
|
||||
int read_input(char str[], size_t n);
|
||||
char *strnlower(char *s, size_t n);
|
||||
int validate_data(struct vendor vendors[MAX_VENDORS]);
|
||||
|
||||
struct search_r search
|
||||
(
|
||||
|
@ -78,7 +77,7 @@ int main()
|
|||
char *file_buffer = (char *) malloc(file_size);
|
||||
int index = 0;
|
||||
|
||||
while ((fgets(file_buffer, 50, fp) != NULL) && (index <= MAX_VENDORS))
|
||||
while ((fgets(file_buffer, 50, fp) != NULL) && (index <= MAX_VENDORS - 1))
|
||||
{
|
||||
/* TO-DO: VALIDATE FILE DATA */
|
||||
char *token = strtok(file_buffer, " ");
|
||||
|
@ -97,12 +96,20 @@ int main()
|
|||
index++;
|
||||
}
|
||||
|
||||
int total_vendors = index - 1;
|
||||
int total_vendors = index;
|
||||
printf("\n>>> Read %d vendors from file %s\n", total_vendors, file_name);
|
||||
|
||||
// print out each vendor's info
|
||||
for (int i = 0; i <= total_vendors; i++)
|
||||
{
|
||||
for (int i = 0; i <= (total_vendors - 1); i++)
|
||||
{
|
||||
for (int j = i + 1; j < total_vendors; j++)
|
||||
{
|
||||
if ((strcmp(vendors[i].merchandise, vendors[j].merchandise)) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char vendor_info[200];
|
||||
sprintf(vendor_info, "%s sells %s for %d each",
|
||||
vendors[i].vendor_name,
|
||||
|
@ -114,10 +121,12 @@ int main()
|
|||
sprintf(vendor_stock, "Inventory %d items",
|
||||
vendors[i].inventory_count
|
||||
);
|
||||
|
||||
printf("%-50s %s\n", vendor_info, vendor_stock);
|
||||
|
||||
printf("%-50s %s\n", vendor_info, vendor_stock);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
char user_query[100];
|
||||
|
@ -137,9 +146,11 @@ int main()
|
|||
if(item.status == 0)
|
||||
{
|
||||
char input[10];
|
||||
|
||||
printf("How many do you want to buy? ");
|
||||
read_input(input, 10);
|
||||
|
||||
if(atoi(input) < 0)
|
||||
if(atoi(input) > 0)
|
||||
{
|
||||
int item_amount = atoi(input);
|
||||
struct purchase_r response = purchase(item.item_id, item_amount, vendors);
|
||||
|
@ -240,6 +251,7 @@ struct search_r search(char query[], struct vendor vendors[MAX_VENDORS], int tot
|
|||
|
||||
if (i == total_vendors)
|
||||
{
|
||||
printf("\n\n%d\n%d\n", i, total_vendors);
|
||||
struct search_r response;
|
||||
response.status = 1;
|
||||
response.item_id = 0;
|
||||
|
|
|
@ -1 +1,24 @@
|
|||
deez lmao deez deez
|
||||
Ae socks 18 22
|
||||
Q belts 10 139
|
||||
Bright books 30 120
|
||||
Alisa kanom 10 19
|
||||
Rich bags 17 450
|
||||
Hey luggage 6 1200
|
||||
Oat watches 9 120
|
||||
Lila jackets 7 380
|
||||
Mary toys 17 39
|
||||
Kitty dishes 11 67
|
||||
Pat comics 22 18
|
||||
Win books 30 500
|
||||
Jay shoes 22 300
|
||||
Mark dvds 10 200
|
||||
Mook earrings 30 79
|
||||
Woot teeshirts 23 120
|
||||
Akraya donuts 35 22
|
||||
Champ phonecases 15 189
|
||||
Pee jeans 9 350
|
||||
Chaiwat pencils 45 12
|
||||
Namhom perfume 13 225
|
||||
Jill lingerie 19 140
|
||||
Jacky stickers 200 10
|
||||
Marisa mooping 30 20
|
||||
|
|
Loading…
Reference in New Issue