From 8811598366e530371a6cfaf86da5675145034ff9 Mon Sep 17 00:00:00 2001 From: Win Date: Sun, 1 Sep 2024 18:25:50 +0700 Subject: [PATCH] Search function --- vendorInfo | Bin 17584 -> 17592 bytes vendorInfo.c | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/vendorInfo b/vendorInfo index 12061c085d678f89e2c41ea698ecbdc599d58f3e..39a912fd22873dd5bf088f8bda60d449478d253d 100755 GIT binary patch delta 3315 zcmaJ@eQ+B`72iF{vQLR^ouVSUDe<{!K0KL7@~7MyN9T`AuAvQ4W(c`I)S0KT7%<2XdV85lxYXiF^n?yw01C5B!=Vd z-b%7V$+JD;PaX@LdG@=XJFxi&OTT-+FL}~p#UyL3 zAg8Q8e4bpk?!w2&qQy-dMHyRP|Iuf@ewchz^r#KEEJz^rwv9Cy-Una>2VdpY#EUir z)^BlL=)tdu2ry^JplusoLoV9>i0x#!I9Ym1QP>=spLNOFlIM$m=J4TCW7BRgLSLqQ zx6)+0wBd`JoeDA@=<^`7)Z;0y8e+5lUcTYZWI>Eyi36S1O8fqGS13dqPW6iuRAHoh z;*&iEaCw!2#uX5hTj|r`E=~WdHaL%*2u(O-1u>e8?>~m2#fDQK8pb#c zQ`4_z-h#c!>9zrq>P9F|S2J2g7)L~1 z##*#1!?IWhvC^#Vpy5G9*&_qXuJY68AgSO@B!hMJx)%Emt&XUA9X4Bo44H*<_pV`F zRkJi(xBdoQRL!nV_zLgo%HgQ*K9E((yALiFH#0n}d|()D`oj3vz#)jh^r-^E_gAwX#HZqX4hknls)wEC1tzXVl z`zW=hhthi2ySYRABk(L5zV|>D>O+4Md`;8S8QbeJL-+&r{Plks#&9Zhh_6>T%O5*c zbKMsg&aJ^#0~erRWBWf0V+O`^FfPED_@`kw_z%;C$ZdJU_AF3r1{3NmcEHyk`QUK@O%c^WdjuZ3 z+$A^e7(NZwW%~1OD|38P=qR;WKC-MWEmfV1$6D%hW7W~!krIamFcHI=ecVbT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}F!c i0k_-R%90I2V2eetrlZ+;vBebcz`l+kKL$e`8~+O%wlDbr 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; };