Search function
This commit is contained in:
parent
854b282a0e
commit
8811598366
BIN
vendorInfo
BIN
vendorInfo
Binary file not shown.
37
vendorInfo.c
37
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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue