From 2656180e259116fae4abfec278326961addd79cc Mon Sep 17 00:00:00 2001 From: winsdominoes Date: Tue, 3 Sep 2024 09:20:56 +0700 Subject: [PATCH] added purchase function --- vendorInfo | Bin 17592 -> 17640 bytes vendorInfo.c | 51 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/vendorInfo b/vendorInfo index 39a912fd22873dd5bf088f8bda60d449478d253d..3155726758641c5bcfc9ce0eac38fa246ccb3843 100755 GIT binary patch delta 2151 zcmZ8ieN0nV6u3vQU{A7*tpg~$v#mbY_nU(tDzcg{V(^SkGs zci*}9h5a<@rvZypDanLMOcN3fE

}C3B1n1#h}i8dRqt84T1ZrU|iF8my)+dJsOK ziZo)6VIy{#4@ST*C>gs0-Px}ndi3!`^8vd0ZvW5ik8MZbU_v#V&{${%NQq{ehT289 z@o_fSwXg#bA0Ov(y_IRr=a|?IX9OdClcObE@8Wts*K>esTyzr~!zPUdA{wpG=z||L zUqfS32DBxavI(I?AZ?gR&+8=QTyTF9Aqk{g#e6dxM1q`8;X+b2miJfELz)V=w4oV$ zWSP&=qRt2flgqVd^)j8I%rA2hvQ?CBO-l?;7@L7*^bDmy$ z<_5xjn9jR`=_X^CQM{dzCUKAf%I*5VrTS-NolPbKoZtGO56(*t+6TW$vy7kM62xa* z=k?!>eyAwQWlcMXhAbf>fy>~aPoc^%PXB~*V>Rsw^&8hx+5%%4E2s?4OiQx-KvBFs zoh`5?b5V2ULq!?rw_{2ED^c+uMd^&_I*wra!7mVu9)HTYoK?qaMb=Sfdpa4$++#@b zdxoxfCJ-m1i@Q7%-ag$o9U4Z^4MdP~hfyx_z@A=?w|gci`pYUkL%Xg`C%Zg&4j1K{ z60N~GUF)u@v4IF~4_mDT*SP1wcMf>FJW+;ZvJ$&I!)$!>30O^KG!v>#%M-ssDk!G; zrk=`-82J~*2|i&j>3fHTV9JzRHaNXzGKRW5Q=_(a&lHw7wahc3>wXm%i;aC+UfL-6 z@eSZVXe|)5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E#!$ZG= z?T%?W3tOC9>6!GP^La{@{=zksKtrJ`kK9+)$jM#>S_&(U+8?Ou@D7$l?8d~0OrPv! z7&E__Rn=H{^hS6FaWYwXB0LjG*}m*CvjE$021Be5G2|L|^qt~(cX)=Py*fO4o* z(LA}a>#U@aSZ6j8i%!Lw?pfS<=ZyxmEYRg9^KQ?F1PNDw(XEt z$V+$RvjWi)LBX1f2!&&)Mrpnp-%p#s&5B|E_wqr1=C))n6)Tu6)z0aqu}xR(6`y=rfuo{ zK8dCiRbNpd_wKYpS9OUH)i;Tv70Bo-VXSro9S5;)@5(qH zTP7~jhmHH>Xh7VKc>F0m44dnu;+N3tFxW`$Ai0$-%u7E9ag|iOpT*$TokbcmzbXto z$Qh37{7>)uzRtjShS}VF3nOJbrjz~*Kdh2g-a}htj~jM88zwFZd8qHVUoQ^7dgf=@ zP#2Sp%MI*Q#iS~v=&LkUg}B48knGdTmut<0&Y8PR-p05j0!hC_n;7TH*L2ROE7it0 z@%-!^WrH^~>UN$_FPAAML9Tbv%Y4>UZz>cGF2Y{PC&!P_RWAwSI%8@2)B24xtv*|6 zOfOrro#Iu-8hm2LtS!pu*+`V;+<=1{N-Fz*3+Lr2>OJ_f0n_ZU#ReC8CImb zf*U9ufU&hcA=d$YK-UFm9D-bSp`3uLDC>cS0>ZHxZ8JMGhWtXJUb7}47V^`#;c95v Ee>%7nRR910 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; + } };