diff --git a/vendorInfo b/vendorInfo index 12061c0..39a912f 100755 Binary files a/vendorInfo and b/vendorInfo differ diff --git a/vendorInfo.c b/vendorInfo.c index 60b2c02..54333aa 100644 --- a/vendorInfo.c +++ b/vendorInfo.c @@ -21,7 +21,7 @@ struct vendor_item } vendors[MAX_VENDORS]; int read_input(char str[], int n); -int search(struct vendor_item vendors[MAX_VENDORS], char query[]); +int search(char query[], struct vendor_item vendors[MAX_VENDORS], int total_vendors); int main() { @@ -87,7 +87,15 @@ int main() char query[100]; read_input(query, 100); - search(vendors, query); + + int query_length = strlen(query); + + for (int i = 0; i < query_length; i++) + { + query[i] = tolower(query[i]); + }; + + search(query, vendors, total_vendors); fclose(fp); free(file_buffer); @@ -110,14 +118,27 @@ int read_input(char str[], int n) return i; }; -int search(struct vendor_item vendors[MAX_VENDORS], char query[]) +int search(char query[], struct vendor_item vendors[MAX_VENDORS], int total_vendors) { - int query_length = strlen(query); - for (int i = 0; i < query_length; i++) + int i; + for (i = 0; i < total_vendors; i++) { - query[i] = tolower(query[i]); - }; - printf("Query: %s\n", query); + if (strcmp(query, vendors[i].merchandise) == 0) + { + printf("Query: %s | Result: %s %s\n", + query, + vendors[i].vendor_name, + vendors[i].merchandise + ); + break; + }; + }; + + if (i == total_vendors) + { + printf("No results found - %d\n", i); + } + return 0; };