From 9ff8098f52eccd30d1793b5bb74298c2343a8cb6 Mon Sep 17 00:00:00 2001 From: Steph Date: Thu, 1 Dec 2022 21:01:59 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Updated=20to=20use=20fgets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2020/2/parse | Bin 8536 -> 8576 bytes 2020/2/parse.c | 18 ++++++++++-------- 2020/2/parse_idk_two | Bin 8544 -> 8584 bytes 2020/2/parse_idk_two.c | 14 +++++++++----- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/2020/2/parse b/2020/2/parse index beaf00faaaff9431e6ea6a660256b7ed63840c3f..0aa5ddcd41e05bab6c5c3f07c1f6a03d841995b4 100755 GIT binary patch delta 2556 zcmZ`)4Qv!e6rQ>5{p_{Z`|n;$>Fr61EkC_hp{1Bc4g~g038J8g1Vm}Ek(5$eDG7RL zIn(o6EO{lKL6c%gEJPI3ND7J+Xeba&iXn*V8_FEzNV>iC#BgybVMLJ*po7GdNq1&!|tl8!mtF=pz`{xDv_YxJISa)s!c6t1`NE)8=E!a{6+YHWmNd?jLpvNsNr$S#_6hKvUV^*&G)vbgsR4#j zI?0e`IX+4%!eoOKQm>gCR2r|Dl&F4@C=(^zU8hU*DUCg*qa-o)ib*Dk+-o>my)$se z_-ky>Kz{;T?ghr#vk&xfevWbWBm>=?f6utU_+HLWGM<7wG|m*6k0hyz&ML~ zVAF_!%2wpO75yHJoL;6xE+~x`2cKD3-lD&Phbb+VbsWkrqgKNGF50+m^*+T`%61`H zq_pUFAS$IdmB^*KOpKK-fhUZ4rYa_FnfeO6Zj`AHnvLTpWTJ@F`<2GBe~dU=#CD`9 z(X!jf;udr&uHbM?KV*bojN?LYU#r3RS1Qqz+&ny8iOjxP)ZH8Y=w2d$lo>yd>*&Zi zg!ua?RwCgJ28{<95Nr4Z*DE{36y8En7mIu#g>O5!m#MaV1sqyp9JaM_2oK&%gc8BX ztzcvj&uL>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7SJ6 zEr@1J%@ss;Jt@SCh~=yn2@L6q=oy&Oc~!H2r_;?)kiDd;2F*20Dvf-^ZTMS*?#h^% zKgV=bvDT2ql~TQ0L$I94A^dHDw(NDZW8hNuFok6H8LiyG{czmi^3<{raY%0+Ii=0e z&J2(!j2c|D8)gh%Iu4#37rhGp94{Z0dXhB@8&P;O$Hm84E8vhG2|UXAoQ*UN)aatU z;4$u@G2qP>NK&QwsI>EY682_6kFgN8@Olh$DQHXy=Q!)UMT0}wF>VupMVCb{MyqR$miE|Bd*TsF_RT3zI!4v1ZH|NlXjRSeMcF zq0PEcaY_qcTVJr5h#kKUZdp~t)6ihG2QQ!%udox%BIzLGFUTW%BH8#}+NE5|Z)1i{ zuETkoHyD$o@<)7yB%MRPi8zR9(Jor7HWu?8DXU`LqfHL@bM5%u#MxPiIxND)wrk*( zT)S!;O4--aqWwwS8|!7DFSn0EqvI`g<}=wi@Vnz3I`Bqb5yeY9`GA*~%TUIvFoE1& z>5MWuz?1LQ#wBhX>hpbCBJ~4-6ZyXR?vT4A3KM7{cVI0z3w(UD)D80p4Fz6ZQsO4D zM+z#}3cWhHqElMvDXi3%=rTDkfgcNfQ0pp( z8kb2cms>Z~yL{Sve}GQ7eDj?jHD)ZEVZxQBJ7B_%nzk=w CH#%|v diff --git a/2020/2/parse.c b/2020/2/parse.c index cf4534d..99f05b0 100644 --- a/2020/2/parse.c +++ b/2020/2/parse.c @@ -4,25 +4,27 @@ int main(void) { FILE *fp; - char* line = NULL; - size_t len = 0; + char line[255]; int valid = 0; fp = fopen("input", "r"); - while(getline(&line, &len, fp) != -1) { + if(fp == NULL) { + perror("Error opening file."); + return(-1); + } + + while(fgets(line, sizeof(line), fp) != NULL) { int start, end; char subject; - char* password; + char password[64]; sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password); - int occ = 0; - for(int i=0; password[i] != 0; i++) { + for(int i=0; password[i]; i++) if(password[i] == subject) occ++; - } - + if(occ <= end && occ >= start) valid++; } diff --git a/2020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