From 0ac77260b3a4a8e3bde915931a2876c02fdb0480 Mon Sep 17 00:00:00 2001 From: Win Date: Tue, 21 May 2024 20:48:40 +0700 Subject: [PATCH] info about strings --- string | Bin 0 -> 16248 bytes string.c | 38 ++++++++++++++++++++++++++++++++++++++ temp-input.c | 15 +++++++++++++++ temp.c | 15 +++++++++++++++ test/main | Bin 0 -> 16056 bytes test/main.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+) create mode 100755 string create mode 100644 string.c create mode 100644 temp-input.c create mode 100644 temp.c create mode 100755 test/main create mode 100644 test/main.c diff --git a/string b/string new file mode 100755 index 0000000000000000000000000000000000000000..65a3894cb156d1e663a18ba5dc4940bcb5429af0 GIT binary patch literal 16248 zcmeHOeQXrh5r22aU>xA=1Ok{UEGbBk;^Pd4x}h%Tk2C8Eg9|1FrF2=}t?jGs!@b)p zHlnR7(+bBzNffF1r+*NsYMLgMtg5O|R1s5BpdYDBq)MntCAVs#bJPS^O%eUT*O~Wb zmc8w{P1--Isyo)*y!rUeyq$f!_tyK~mtzOIf`NcwsuG_ND2>%AO_U5HAEgGcsAv%@ z;ad|M#Zr)$NS(4r6$7iHo56BkL;5P;;PX^ zvX_6C`pKN_PCgC6K$`q^_)F*j#N3U;+FWduW^u8#oR3hxG2)Cv5pmZEcb#y|=P4g^ zt|!(6KP^;GFW10^q{(j~ytre8^YTveXO20Lj=X6n{+)cigqzW17~$pHm0B?8e4hdw z*5&;YpXS4qZ?W^BQ~jA!dBu)YvVTwWj#Q#CmCO`I8b@08H125*=d~%&tZzqx&F=*Lwk+aNHDjOGR z#S8<+MBK>RX3jR!CU_Y}e8e;ck{L6VJZ*{LTry)12=u~%vPbMc(B0l)>1>9Q7|OMxBXl(gqpb@5%D;o618hA0 z3k^vaGF767bl-pa>o5$0;yB1id|%@G!AUxK({$fqy+-=2Q3-SIA1q(or}Q|+a11a_ zyY%jHech$UvCA~$(#!ib8E(4t+$S{6y7V~a9g38D7nt1M;p_+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ointer + text = (char*) malloc(1 * sizeof(char)); + + printf("%p\n", text); + + // the size function will print out 8 bytes as it is + // calculating the size of the pointer, not the actual + // value itself. to do that, you gotta dereference it first + size_t size = sizeof(*text); + printf("%d\n", *text); + + printf("Size in bytes: %d bytes\n", (int)size); + + while(c = getc(stdin), c != '\n') { + text[i] = c; + i++; + + printf("===========================================\n"); + printf("Num of characters: %d\n", i); + printf("Current char: %c\n", text[i]); + printf("Address of current char: %p\n", &text[i]); + printf("===========================================\n\n"); + char* deez = realloc(text, i * sizeof(char)); + //printf("%s", deez); + } + + printf("The Text: %s\n\n", text); + + // size_t size = sizeof(*text); + // printf("Size in bytes: %d bytes\n", (int)size); + return 0; +} diff --git a/temp-input.c b/temp-input.c new file mode 100644 index 0000000..8abcc30 --- /dev/null +++ b/temp-input.c @@ -0,0 +1,15 @@ +#include + +#define LOWER 0 +#define STEP 20 +#define END 200 + +int main() { + float fahr, celsius; + + printf("Fahrenheit\tCelsius\n"); + for(fahr = LOWER; fahr <= END; fahr += STEP) { + celsius = (5.0/9.0) * (fahr - 32.0); + printf("%3.1f\t\t%3.1f\n", fahr, celsius); + } +} diff --git a/temp.c b/temp.c new file mode 100644 index 0000000..8abcc30 --- /dev/null +++ b/temp.c @@ -0,0 +1,15 @@ +#include + +#define LOWER 0 +#define STEP 20 +#define END 200 + +int main() { + float fahr, celsius; + + printf("Fahrenheit\tCelsius\n"); + for(fahr = LOWER; fahr <= END; fahr += STEP) { + celsius = (5.0/9.0) * (fahr - 32.0); + printf("%3.1f\t\t%3.1f\n", fahr, celsius); + } +} diff --git a/test/main b/test/main new file mode 100755 index 0000000000000000000000000000000000000000..14c9213c6204da80d1a294f8c7563024b3d70c31 GIT binary patch literal 16056 zcmeHOZ)_CD6`wl?a1yW&0*QeXZ<8RIwq9)hSR~YN#$L0g1{|`y~7h$fFkY)1zWMlTOTnW~l5VybaI9-_P)A!Ht^$jcKiPrM>he|bXA zC*}nIx6yg{QG+@ZO&*2t^9~Wuk1gcSh<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;#Y zI}8aaWv>Ri#$*qsq2;+& zaPfWIvNIWb*n-~yGsB`cV<#OeHkeEf1I43R;OWkD#Wnm8k7czUXxeL7#=aH{R@}E7 z-q*CZtr^U)Ey6NPsx?~<2y1uy{#{M&*8bMkgGQ&-*|e+Ouy}t!lvn%9CI0@s0>xU` z3-EF4|8d7b(O0(Q#BA3V@(zzoSeEMV12y2R}#*t!h8G5jj z@gC?t?PALi99}scQY>^B$@oLH_wM=RWt?Pr z-}A?B10Uyl%;)(aBYtn8V2qeM=JUKP4mLbx=1)+7j69zN7b*Vye;uqicVj-!*BJRb zkmF}R#%}^2=Yp*Be2}qDb$eI*WELl&fFU!V=cA01xuCc)OqUSN!8&&BNxdpU}vgFykddnd4^j1t{S8bC?V5gJgey z|L^$t6Pog5Jk3NxfB#p(4(mGQJ%ld&yvO?_{r;>o&H$&SPbS<`a_xUo9@qO^Y zu}2?U#rbS;-zz2u1n++o=J9p>DcI13`Mm#aawB>RQKO)EWIp3ZP~+wE^W+Ti>xxWO zU>@UQAba^d53M31$H~nwkM*TMMjOY^^S~P7`~9&muPmqj{c$qC+UpEu=6jLHp4Zi+ x22WC8pMpyKEaZ6j^B3SJmR2yEOlgTb0KeAHk=J{{qq3wk!Yu literal 0 HcmV?d00001 diff --git a/test/main.c b/test/main.c new file mode 100644 index 0000000..61a7bf0 --- /dev/null +++ b/test/main.c @@ -0,0 +1,50 @@ +#include + +int main() { + + // declaring and defining the 14 digit numbers + int digits[] = {3, 4, 2, 1, 5, 6, 8, 3, 1, 5, 1, 5, 6, 5}; + + // declaring the variable for the total of the first, third, fifth elements and so on... + int sum_odd; + + printf("=====================================\n"); + printf("First set of digits\n"); + printf("=====================================\n"); + // loop through the first, third, fifth element and so on + for(size_t i = 0; i < (sizeof(digits) / sizeof(digits[0])); i += 2) { + // multiplying the value of each element by 2 + digits[i] = digits[i] * 2; + printf("Element %d: %d\n", ((int)i + 1), digits[i]); + + // adding the value of the current element to the old sum_even value + sum_odd += digits[i]; + } + + // declaring the variable for second, forth, sixth elements and so on... + int sum_even; + + printf("\n"); + printf("=====================================\n"); + printf("Second set of digits\n"); + printf("=====================================\n"); + // loop through the second, forth, sixth digits and so on + for(size_t j = 1; j < (sizeof(digits) / sizeof(digits[0])); j += 2) { + // multiplying the value of each element by 2 + digits[j] = digits[j] * 2; + printf("Element %d: %d\n", ((int)j + 1), digits[j]); + + // adding the value of the current element to the old sum_even value + sum_even += digits[j]; + } + + // add the sum of sum_odd and sum_even together + int total = sum_odd + sum_even; + // print out the value + printf("\n"); + printf("=====================================\n"); + printf("Total: %d\n", total); + printf("=====================================\n"); + + return 0; +}