diff --git a/vendorInfo b/vendorInfo index 39a912f..3155726 100755 Binary files a/vendorInfo and b/vendorInfo differ diff --git a/vendorInfo.c b/vendorInfo.c index 0e30775..a50e593 100644 --- a/vendorInfo.c +++ b/vendorInfo.c @@ -84,18 +84,27 @@ int main() printf("%-50s %s\n", vendor_info, vendor_stock); } - + char user_query[100]; read_input(user_query, 100); - - // convert string to lowercase - each character one by one - int user_query_length = strlen(user_query); - for (int i = 0; i < user_query_length; i++) + + while (1) { - user_query[i] = tolower(user_query[i]); - }; + if ((strcmp(user_query, "DONE") == 0)) + { + break; + } - search(user_query, vendors, total_vendors); + read_input(user_query, 100); + // convert string to lowercase - each character one by one + int user_query_length = strlen(user_query); + for (int i = 0; i < user_query_length; i++) + { + user_query[i] = tolower(user_query[i]); + }; + + search(user_query, vendors, total_vendors); + } fclose(fp); free(file_buffer); @@ -132,6 +141,10 @@ int read_input(char str[], int n) - query: search query - vendors: the vendor table - total_vendors: the amount of vendors + + Return values: + - i: Item Number + - 0: No results found */ int search(char query[], struct vendor_item vendors[MAX_VENDORS], int total_vendors) { @@ -145,27 +158,37 @@ int search(char query[], struct vendor_item vendors[MAX_VENDORS], int total_vend vendors[i].vendor_name, vendors[i].merchandise ); + return i; break; }; }; if (i == total_vendors) { - printf("No results found - %d\n", i); + return 0; } - - return 0; }; /* Purchase function Parameters: - - item: The item that the user is purchasing + - item_id: The item id that the user is purchasing - amount: How many items that the user is purchasing - vendors: vendor table + + Return values: + - */ -int purchase(char item[], int amount, struct vendor_item vendors[MAX_VENDORS]) +int purchase(int item_id, int amount, struct vendor_item vendors[MAX_VENDORS]) { - + if(amount <= vendors[item_id].inventory_count) + { + vendors[item_id].inventory_count = vendors[item_id].inventory_count - amount; + return vendors[item_id].inventory_count; + } + else + { + return 0; + } };