From c182be9758c2681155a70de72f62b9bc35a8a5f4 Mon Sep 17 00:00:00 2001 From: Win Date: Thu, 29 Aug 2024 11:31:21 +0700 Subject: [PATCH] putting data into array of struct --- vendorInfo | Bin 17184 -> 17384 bytes vendorInfo.c | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/vendorInfo b/vendorInfo index c90780c8cf1d76541018976877a871247926ed8d..7b2cb413b6d160c17a654edeed50e7fc6d065981 100755 GIT binary patch delta 2653 zcmai0eN2-_7{7Z`jWXs|1cw)SP@|`nN+Bmpc!A{ z)>Jq2Wd5^cF1nfhu|-lz(1b4~;y+u&8Kz5?v1F3+&jynye$4KQLv=?QJrwXXA3*iZ?z)2rOlliyT2PIrxsg1H+N#R4A+n}0l~k*vD+Cn& z!x4QtQ!3X1*Rkm#bmjD?8iZ7+nPZ1j8np;)+Q}DcgNd&Vvz>8BjDtDSlJC?;jL8G_ z`#73ZYm8*KCYE$+a(2m*VnsI~mf0(0M+Ckm0xatS8+%?K^lo8!}ug9f38 z@#~)62#b9~ZWvuIrqp8?q84)Rm`6KGf#6Ji-;MgPaeTUjMworq?`~44Uyt47ZGEa? z5Qad94ZCFTgFri^a#MYQc=hHK308ix;yDX?YIy#SU~q(PMqpSVQ~E@Fj?C(_pswN* z)^#{u1cS0~H~=;Q1MPczXQ0oa+%fOX+&h63#fT~bFaBai_n<%7dlx7h#Wzd=+1F14 zjaUH-d`S&^mQeihwQv|9AhQ_B5+&+^0uQLZ!`pj{I@YpK@@OZ_o;LZw*sC(0lzoF# z9mob-$YoLvyI)fB_)qVi$;42E!1I4asDlU{FkcqJH_Qgw2bgzUuI;BYlZV3T+<|m% zd*zH3S!{^Nf`>@|pAcC-HrJjp?CrhV0mICV!}3n{PC%DVy=R#A65~&u1Hm^)1y~-& zu7&fV%X2-1U;QUOF87Ql%C#&`*`w;L)gR5BMq&$l*k1p2vSa@PbcziOyos9-XbkS_E;^WRS}u0A7Xm5L~Hzj#c{ zY-R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>|OFGNH;2K6h97Vvgp-?-73M0tmdR^p9wOmue;X3M67voY?oh!^Ds=iQws^Tmz%JuWeGpRq4oYCz?~uGa z6JIg$0j+g_w>A$Ov#!=dQ!r2)!|QRgwuM%M6bL!vSTGkUB2jGbjpT%V0f%!JqE)cV-Sx`62U8 ze5q!1lKF_NPo>J+XtxRZWQkW=@2o@2PV$LwidLIVi?mvKkRjkI5~R#^GkzBkHXY1=<`G^`f;wxH&}IU<~ #include +#include #define MAX_VENDORS 20 #define MAX_FILENAME_LENGTH 4096 @@ -37,10 +38,30 @@ int main() unsigned long file_size = ftell(fp); fseek(fp, 0, SEEK_SET); + // read file to buffer char *file_buffer = (char *) malloc(file_size); - fread(file_buffer, file_size, 1, fp); + int index = 0; - printf("%s", file_buffer); + while (fgets(file_buffer, 50, fp) != NULL) + { + char *token = strtok(file_buffer, " "); + strcpy(vendors[index].vendor_name, token); + + token = strtok(NULL, " "); + strcpy(vendors[index].merchandise, token); + + token = strtok(NULL, " "); + vendors[index].inventory_count = atoi(token); + + token = strtok(NULL, " "); + vendors[index].item_price_baht = atoi(token); + + index++; + } + + for (int i = 0; i < MAX_VENDORS; i++) { + printf("%d | %s %s %d %d\n", i, vendors[i].vendor_name, vendors[i].merchandise, vendors[i].inventory_count, vendors[i].item_price_baht); + } fclose(fp); free(file_buffer);