From 48b6e665c97e2270b49abd303aab58b20a7f2acf Mon Sep 17 00:00:00 2001 From: Amanda Puchille pinha Date: Mon, 9 Dec 2019 13:50:12 -0300 Subject: [PATCH] C Piscine C 03 - OK 100% (2019-12-05) --- c_piscine_c_03/ex00/ft_strcmp.c | 21 +++++++++++++++ c_piscine_c_03/ex00/t_a.out | Bin 0 -> 8660 bytes c_piscine_c_03/ex00/t_main.c | 26 +++++++++++++++++++ c_piscine_c_03/ex01/ft_strncmp.c | 28 ++++++++++++++++++++ c_piscine_c_03/ex01/t_a.out | Bin 0 -> 8660 bytes c_piscine_c_03/ex01/t_main.c | 26 +++++++++++++++++++ c_piscine_c_03/ex02/ft_strcat.c | 39 ++++++++++++++++++++++++++++ c_piscine_c_03/ex02/t_a.out | Bin 0 -> 8644 bytes c_piscine_c_03/ex02/t_main.c | 15 +++++++++++ c_piscine_c_03/ex03/ft_strncat.c | 29 +++++++++++++++++++++ c_piscine_c_03/ex03/t_a.out | Bin 0 -> 8612 bytes c_piscine_c_03/ex03/t_main.c | 16 ++++++++++++ c_piscine_c_03/ex03/t_roman | 17 ++++++++++++ c_piscine_c_03/ex04/ft_strstr.c | 33 ++++++++++++++++++++++++ c_piscine_c_03/ex04/t_a.out | Bin 0 -> 8612 bytes c_piscine_c_03/ex04/t_main.c | 14 ++++++++++ c_piscine_c_03/ex05/ft_strlcat.c | 43 +++++++++++++++++++++++++++++++ c_piscine_c_03/ex05/t_a.out | Bin 0 -> 8652 bytes c_piscine_c_03/ex05/t_amain.c | 17 ++++++++++++ c_piscine_c_03/ex05/t_main | 40 ++++++++++++++++++++++++++++ 20 files changed, 364 insertions(+) create mode 100644 c_piscine_c_03/ex00/ft_strcmp.c create mode 100755 c_piscine_c_03/ex00/t_a.out create mode 100644 c_piscine_c_03/ex00/t_main.c create mode 100644 c_piscine_c_03/ex01/ft_strncmp.c create mode 100755 c_piscine_c_03/ex01/t_a.out create mode 100644 c_piscine_c_03/ex01/t_main.c create mode 100644 c_piscine_c_03/ex02/ft_strcat.c create mode 100755 c_piscine_c_03/ex02/t_a.out create mode 100644 c_piscine_c_03/ex02/t_main.c create mode 100644 c_piscine_c_03/ex03/ft_strncat.c create mode 100755 c_piscine_c_03/ex03/t_a.out create mode 100644 c_piscine_c_03/ex03/t_main.c create mode 100644 c_piscine_c_03/ex03/t_roman create mode 100644 c_piscine_c_03/ex04/ft_strstr.c create mode 100755 c_piscine_c_03/ex04/t_a.out create mode 100644 c_piscine_c_03/ex04/t_main.c create mode 100644 c_piscine_c_03/ex05/ft_strlcat.c create mode 100755 c_piscine_c_03/ex05/t_a.out create mode 100644 c_piscine_c_03/ex05/t_amain.c create mode 100644 c_piscine_c_03/ex05/t_main diff --git a/c_piscine_c_03/ex00/ft_strcmp.c b/c_piscine_c_03/ex00/ft_strcmp.c new file mode 100644 index 0000000..6a99275 --- /dev/null +++ b/c_piscine_c_03/ex00/ft_strcmp.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/02 21:32:49 by apuchill #+# #+# */ +/* Updated: 2019/12/05 00:02:15 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + int c; + + c = 0; + while ((s1[c] == s2[c]) && (s1[c] != '\0') && (s2[c] != '\0')) + c++; + return (s1[c] - s2[c]); +} diff --git a/c_piscine_c_03/ex00/t_a.out b/c_piscine_c_03/ex00/t_a.out new file mode 100755 index 0000000000000000000000000000000000000000..cf6cf21be818b77d4b7629d434c8a8e86ad59714 GIT binary patch literal 8660 zcmeHNU1%It6ux5;jp@%OQfulDOpB?ll(tD*X^X*)?&uUZwc0F7X}E57H_g(`54$^> zf`ODIu+!rgeDLKY3M`O@7z0+o!t~4`sBkL zICIZ;{`TB+XW-7<{o&5?-G>-cY8V@RfH4*TH`XyW!Bj|$Z3F9I&QEl_qMg#-c#X7` zq*TItBFeJ>N6x#nx4J4_M0{hVjyV{$F_a^iJUGuLhO;C|s?ImG5tD%_MUw#$u9c#^ z*0NDAU=jh%Y2VG9xiqR>YaQKItrPO_a#z8i8OT8`Bt2KdmVqmPN`C} zuD)0%n@$d#S<7G9KNSl`^Zm%N6ZX!xA~$?EHwNBK4#atKpm$K<%6!vKK3a1k!qqvX zMP6xL4~umTb#!%jELcCP%U#Fnk=7OWoM3X}d?3X$=lXjFQ+z0!2EKQ`wc7*&#k)lP z_hQb^40>*pb@>{d`s$qoguU^UkM28{I8R0YtG;F@U$YZH*qe{$>)s>eQhu(&$Bw_M zg^sz;gj&@%V4@qMnT$~$M-=)Ucy9NTq%uZxsmFL2qf0?m;$e(IC}}OJ#-b|yO|UeuNBffHyanDS4nvOl{WTm<&X?||O{zXN^;{0{gXxW5iW zbn{Q$99h*(W94gYiITJyb6@CIWL1wDOM%a8+aRw<`T4dZtGUiwfr$h6a2s1?WE+1B zHr>(?(uwdb^<#HfF!15^V9vO8LAy1n1SV+zvPc^eOIsQ%DyFuym@Ab^2*Pj5pmKtP z^}GKz=ew^JB#C;@FBRxV^2WTLA6eF|x}UM7&@HB$$Y9mcdkw_pUTf1&5PQwee=a=w z9i&|3Hq75j^E|}sQd|gGb=M$eJN~43iefUvqmPNzhr6`?N21W1Y9t+oc+GU z1!*6*$IAY&kJ|LAg?O@0niKC~9qhMBm2Y3cU>O&!NY3gUM{T1aD^GS=-XRg!ei{?d ztrx<$U&2RzF(-!M5SXCdYim(IKTGS>ea)sFUtmM2Y3w@+q{0mw7Xsft*lO);%F8&CKvE$KrRE?_dh?hC2yAs$ls_}&S(qR8kG#!ma z2c?c>THB7QE%7~SrmfWxS`RqF0aw$urV-Apq2a#5uXNvo zNTxmXM(lwbcC+e>H{5YDk<{X;;46pnMn8s6W>6T^v^kxk&tJWA>J z^k!Yx{r%D806RqAG-}vNGcF%LE~A02h;J9-OOMhhQ{uW69Dv3BAHa48)A=9;JOjo^ zqM#$VdU3c4cU9rjRhYi1(Dy|;+oiKvP>{~wy?Pa=&+F&O%k$)7o)rrq+E}5HOXBv_ LZPB{b!EgTy#DXjr literal 0 HcmV?d00001 diff --git a/c_piscine_c_03/ex00/t_main.c b/c_piscine_c_03/ex00/t_main.c new file mode 100644 index 0000000..ed5bc08 --- /dev/null +++ b/c_piscine_c_03/ex00/t_main.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: galves-d +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/29 00:02:08 by galves-d #+# #+# */ +/* Updated: 2019/11/29 07:05:23 by galves-d ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int ft_strcmp(char *s1, char *s2); + +int main() +{ + char s1[] = "Nada a ver"; + char s2[] = "Teste de Comparacao"; + char s3[] = "Teste"; + + printf("s12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", ft_strcmp(s1, s2), ft_strcmp(s2, s1), ft_strcmp(s1, s3), ft_strcmp(s3, s1), ft_strcmp(s2, s3), ft_strcmp(s3, s2)); + printf("\n\ns12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", strcmp(s1, s2), strcmp(s2, s1), strcmp(s1, s3), strcmp(s3, s1), strcmp(s2, s3), strcmp(s3, s2)); +} diff --git a/c_piscine_c_03/ex01/ft_strncmp.c b/c_piscine_c_03/ex01/ft_strncmp.c new file mode 100644 index 0000000..a0f5ea4 --- /dev/null +++ b/c_piscine_c_03/ex01/ft_strncmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/02 22:59:36 by apuchill #+# #+# */ +/* Updated: 2019/12/05 00:05:18 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + unsigned int c; + int diff; + + c = 0; + diff = 0; + while ((c < n) && !diff && (s1[c] != '\0') && (s2[c] != '\0')) + { + diff = (unsigned char)s1[c] - (unsigned char)s2[c]; + c++; + } + if (c < n && !diff && (s1[c] == '\0' || s2[c] == '\0')) + diff = (unsigned char)s1[c] - (unsigned char)s2[c]; + return (diff); +} diff --git a/c_piscine_c_03/ex01/t_a.out b/c_piscine_c_03/ex01/t_a.out new file mode 100755 index 0000000000000000000000000000000000000000..67609f51ab6504d101375d23b362f509d00e958a GIT binary patch literal 8660 zcmeHNUu+ab7@wm>u@v@d6zjjZq9tI2+JXcy#H)672|YyVMPtOtwRfc_*X!l}2s|`t za$M47L(&(G518=a0}nh9C8QcciV#Tppp7w+1S2FAvQ65gniva4&fhmPd)>W)4?bzK zUotn}_nU9N`Q|sX>FiFwzcYLHLB>LLj14bgjA!>-M{d{$W4Hl#SdN(h-F`I4>j*7D$s)8}IsZOa@JNX)+M9 z>!m7x>)Ei^Kjs>IneyZBZ_RiNA8$O&DGY3+c1W#r928Hd9H>Tpznv;-S z8$-6pUs~5KVqH5sx;s2ASU<|kUB}v*))jkB6msJ{ljiwD13iOjo-O2H-#cD)n?Rxd zt`PrToAZ5xo^7%yURdR~Oa&m@+n?gmzH^21bo`(4YgX}^RR^-Y@o2v89wC>7=c;SR zuAN5b4)>YRYj}fA@}nS=F^Z#9fv?7M`x0q7V>Fj#sJEbYC8A6FAnFJ}T1(1tT$lcd zXBo@F#$&>Eqj-h#r{d+o+fI4}{U53YVPjh}9i%I-W03Fm;Wi93}IA2kPghJyI57b6; z4&9l;V-Z@&1^MhblrJO)HoUe0d8K;b1X+VZ@yB$@&pKs~!ww{1AYdS1AYdS1;Qzuv z%(QNr*3i6Z73Zwj%w@x&%r6^LRJDzdoVN|<6=P;3dP6I{p`g;x6eFPgvI0yyHV;4R zl6J1Xy)-Wx57S>((>CVpsAElN=NiMM+bp7eaw#%Wym7?1aU!IZ>EJNEUi!^TzcYN=0U*m15{fsc7Y$z7TRK?eHpz`V!E}&-i@r zJ)AMM_rjYaT65nn#CbO?&BWoEJ=+nU*mR>rb3Mpw9N$E9Rm0S<&B*JURz$ zB=!fIXJqpv)M=?+>9m*Lg4$^r*P&jM>IC}J`w#km_YLvl^xUmfFzPHuofL>=Ty&xm zoS;+`IPPp&@SITKS?9S0Pq+J+vr>XI6W8;!bNeqEX!{2k-7a3VW8-%8Y^QCEb=uL> zR{is*m~$2Rd`(GN7+CUP8K;~HA1o5JjFZk+K3Jq`87G`$KA5~GEaMBO?1RaB(lU-a z86PYXwv1!WyMU4FO;mRAq#Zk9N54R>$C2wXnQJR~*xS1?8`FNZ3p=xG>ra;PnO3Ib zZ`-(8x|rR2!J#vsw!G4^34WE9&El8dQ@V~m-Gr)RPo*V7PlX zL*Voe&=}hlPsH`O{;_zO1Kgd&nNd$9_16anvhiHJH$EsamTzm{rne+s)bs6aN@?4u zl#MRZUPXj6YiRga-Q@ZBDda=qt!du$&btXUm1}emhmcNZ=ti7@!}4@ZFetc>sQ17I zRX?KY`*;U%z(Bx2z(Bx2z(Bx2z(Bx2z(Bx2z(Bx2z(Byjf0%)$)y;b-y`~7KtLu30 ze%{-^pYJQia|!l#E<75cOFMB%&UC35~K`b4|~_cq+|+>%g0<_c6x5)&{|B&I*$nrC)Q}ar?Y@p4>A}F6QZ50l}jWk!#|TTIFcb`mnzN-ZfjY literal 0 HcmV?d00001 diff --git a/c_piscine_c_03/ex01/t_main.c b/c_piscine_c_03/ex01/t_main.c new file mode 100644 index 0000000..26323e8 --- /dev/null +++ b/c_piscine_c_03/ex01/t_main.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: galves-d +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/29 00:02:08 by galves-d #+# #+# */ +/* Updated: 2019/11/29 07:06:27 by galves-d ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int ft_strncmp(char *s1, char *s2, unsigned int n); + +int main() +{ + char s1[] = "Nada a ver"; + char s2[] = "Teste de Comparacao"; + char s3[] = "Teste"; + + printf("s12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", ft_strncmp(s1, s2, 5), ft_strncmp(s2, s1, 5), ft_strncmp(s1, s3, 5), ft_strncmp(s3, s1, 5), ft_strncmp(s2, s3, 5), ft_strncmp(s3, s2, 5)); + printf("\n\ns12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", strncmp(s1, s2, 5), strncmp(s2, s1, 5), strncmp(s1, s3, 5), strncmp(s3, s1, 5), strncmp(s2, s3, 5), strncmp(s3, s2, 5)); +} diff --git a/c_piscine_c_03/ex02/ft_strcat.c b/c_piscine_c_03/ex02/ft_strcat.c new file mode 100644 index 0000000..e227dd0 --- /dev/null +++ b/c_piscine_c_03/ex02/ft_strcat.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/03 10:21:00 by apuchill #+# #+# */ +/* Updated: 2019/12/04 13:52:33 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (*str != '\0') + { + counter++; + str++; + } + return (counter); +} + +char *ft_strcat(char *dest, char *src) +{ + int c; + + c = ft_strlen(dest); + while (*src != '\0') + { + dest[c] = *src; + c++; + src++; + } + dest[c] = '\0'; + return (dest); +} diff --git a/c_piscine_c_03/ex02/t_a.out b/c_piscine_c_03/ex02/t_a.out new file mode 100755 index 0000000000000000000000000000000000000000..e27ad2f2a5408043cbf18dba6cb4108204b508ec GIT binary patch literal 8644 zcmeHNPiP!f7=P0=x+H0LD=N`OoD?IiwoR3ysSw#{1}E6mv`wrC;dQfrvP&kLWoL#q zhd^L0bh<3;(X$9%dgwt!!9Qse><(2xs|?bwfctfR`wwoG|!5l$llxP zPR4T38-;Wcox*r01>Q3PfNbJ@M|Q=R zT*#ZPgu{3j1>U0qfb6z>cYr;G^Q37NbNN}}593(^?3zPSvmW#L9NPw5~X| z+f&Cxx}$Awe2vjwr}6sw-iRBMURqP9SF2Tjz6rfDbx*I@_w{n8gXb~5%rF*NeCK7+ zxkmFj8nxf_)LMDpSJ0es#Mt?n=erlbHv9?H_|>H!^~&&ds5e;cZECF8z+bxWXt!&< z6cEi-8UD~4w}M_LNG(6s?auy)UbY+hsox##^XL_Nj(uSTAx})N*62Yo+Ffl9{0gNx zP{;Lj<*7TUM$R_}zCc~g;=(q5!7N#NJlyyJ8o5aHv|-SDQBaPmmlldfs-GPr=}M(d zOC44R%r3K-^b}T1o353hqFh(@}UL zImeUPIX-JAiYa!s7^}wVkj*_L=QB9x#i90c4c|9hQL3!i8ycBO|T6*isgQ9GRrq9)aqQCx%eg^ + +char *ft_strcat(char *dest, char *src); + +int main(void) +{ + char dest[20] = "Hello"; + char src[] = ", world!"; + + printf("-----\ndest = %s\nsrc = %s\n", dest, src); + ft_strcat(dest, src); + printf("result = %s\n-----\n", dest); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex03/ft_strncat.c b/c_piscine_c_03/ex03/ft_strncat.c new file mode 100644 index 0000000..39371e7 --- /dev/null +++ b/c_piscine_c_03/ex03/ft_strncat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/04 14:01:10 by apuchill #+# #+# */ +/* Updated: 2019/12/05 13:11:00 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncat(char *dest, char *src, unsigned int nb) +{ + unsigned int c; + unsigned int d; + + c = 0; + d = 0; + while (dest[c] != '\0') + c++; + while (src[d] != '\0' && d < nb) + { + dest[c + d] = src[d]; + d++; + } + dest[c + d] = '\0'; + return (dest); +} diff --git a/c_piscine_c_03/ex03/t_a.out b/c_piscine_c_03/ex03/t_a.out new file mode 100755 index 0000000000000000000000000000000000000000..dcac07ac49becec04e4977630a040d499c8f8508 GIT binary patch literal 8612 zcmeHNPe>eB7=Kf>wZ>#OP>RJCrcz64F#f4Arme7s44u$yYmEzSA-wEA-6iWPJF_$% z0+x;7WLU60_T-_56ne-Z6bh1R5+VtOc<3RA90IXrEfzf59Nd1tnYZrD7<=yFeeliu z{=D~l-}}w1yqV{t=YQ|M!kE&)*xXBuu@LE{CdTHON)}^pkm{tIkB)q-eWi_khNxc@ zzxzTDILBxL&d0Sc#{FHK@nL_A37=|XR1SMtq&YX!SIm0fAl}kpS`4KvQ55{fdUrT; zUYB#jEGCS-P!O++2mw^9=uz`)1DXY1y*}XaOgcA{E>Nc+-jKk1M*zSF?|ZVZzT|Y? zs4qB(cS+#ACII03*1HGn8k{E$vyjbCig*yu6nMiT58o@kS}DPKG5>WopW@m4#I)o4 z@9!;vhi3=^KZxOG+$)}wAtIdfvm@gpo(w$?&MmDyCxI5v2|dG(Vif2395-gC64N<8 zV-^m?tHI!T!}yxuetPTVd~&*e7xvc|rtzq+SpdKf;(6~2=ehWQ)z>EQsBr|o7q9la z5NXfv^!&L`Khe&f8y6Whz#I9H9~?3n1CB7AcnAF*=!K=aYiXu-2)>YrO21>WGt@?? z1xIb9H&qwwqqiwX{vpy)Qm@qRkCz8;9=1y3QBzQkP(UTc@35z66nb*mL{Dlqmm(k1 zPKr8~yS`2LE}uI7&7)g`D~5fhpJFPhLduS`I11b0vf+->MRtv2bfLA)0cQpidIa-= z2jsA3<@p9JL#fw7^<0=W%=FZWGbgC7Y=SzGyh{rF8>-9ad%_1_QX~VC0m*=5Kr$d1 zkPN(tftYUnp<7pXbgQ^+#kSV83VN++8)$S}+p(h+>tX12Yq<0e3thvm#nvjN6~)pj zn@_6M>Lxn&tt_nSc5K_$Hmv)h+l~FD9kvjC7P^LQ4Fx~cwnE>nQslb!?1mDW#~asX zH(h9kZ9BSQJ&ar*2#e_&$bUeQg@G`oN~?+$-Prt|rt;_SH-?=8FWz1Bh_jy3)~H^N zJ=V*`r@GyQS2f*cx~1)`X}{B?z4Lg<>y_h4zrbqe{@H#P)F=@b^GM2&isSAO)Q_@wY25X zJTUuK^wPc2i+3y7Duxa%Ry#p`wev5!GIqZF)&purE>t^F%VGw>%|D5S47P|4^$7L# zzmLWz11ASh4V~^~-H?`4+A!5&wbN)Z3Q5<&F|QyHGVl1>)QG@X&h0oOfY5_}<_jGL@) zDxS@=L43$)U`y?E*%lu-mfF{y?-fXe6!*jqf!7`1{q6z3L-;tqgMW;aT9}S}Kv%CH w4fwHukMAa)|38S(p`Y_D1u>OQmG`fQd)C99_4t@|`0+(tu4`oNqnojR0W^1?!vFvP literal 0 HcmV?d00001 diff --git a/c_piscine_c_03/ex03/t_main.c b/c_piscine_c_03/ex03/t_main.c new file mode 100644 index 0000000..d5cadc7 --- /dev/null +++ b/c_piscine_c_03/ex03/t_main.c @@ -0,0 +1,16 @@ +#include + +char *ft_strncat(char *dest, char *src, unsigned int nb); + +int main(void) +{ + char dest[20] = "123"; + char src[] = "4567890"; + unsigned int nb = 8; + + printf("-----\ndest = %s\nsrc = %s\nnb = %d\n", dest, src, nb); + ft_strncat(dest, src, nb); + printf("result = %s\n-----\n", dest); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex03/t_roman b/c_piscine_c_03/ex03/t_roman new file mode 100644 index 0000000..5594cc1 --- /dev/null +++ b/c_piscine_c_03/ex03/t_roman @@ -0,0 +1,17 @@ +char *ft_strncat(char *dest, char *src, unsigned int nb) +{ + unsigned int c; + unsigned int d; + + c = 0; + d = 0; + while (dest[c] != '\0') + c++; + while (src[d] != '\0' && d < nb) + { + dest[c + d] = src[d]; + d++; + } + dest[d + c] = '\0'; + return (dest); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex04/ft_strstr.c b/c_piscine_c_03/ex04/ft_strstr.c new file mode 100644 index 0000000..2783a1c --- /dev/null +++ b/c_piscine_c_03/ex04/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/04 14:36:51 by apuchill #+# #+# */ +/* Updated: 2019/12/04 21:38:22 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + int i; + int j; + + i = 0; + if (to_find[0] == '\0') + return (str); + while (str[i] != '\0') + { + j = 0; + while (str[i + j] == to_find[j] && str[i + j] != '\0') + { + if (to_find[j + 1] == '\0') + return (&str[i]); + j++; + } + i++; + } + return (0); +} diff --git a/c_piscine_c_03/ex04/t_a.out b/c_piscine_c_03/ex04/t_a.out new file mode 100755 index 0000000000000000000000000000000000000000..a5d2aa5d428383aa655926fe9c90b13d6531e29a GIT binary patch literal 8612 zcmeHMO=ufO6rQc@)Ywi|DM@j01Dg={k2aQFJGH?EIb`XYT5X!x5DHlgwlg%k&yuUfdq>tJd$`MK#oM)rgvSiuf#ala!$)M{?Srqv#PBOJE zY{~6%p2_B>Gmk=Eya^COP@OWv@tpx}67P@<*myh^O{Ah}#JqTyCEjV7Pd@SfNDkB& z$z;><H3{BQMjNjx+{$amv8&#~-w{jVm*Uw_R!Kkob|3=ePc zNp1)-86zBNiuft~Zv$i*_FUS~4v{Y=@c0TH>e+x^CE5BPY=ZzXN&!>K12x z+&sAZ$u=;aYVyhv1PmzsZ+df?bZ;U)-8-|Gn1N5y4W&AMdiT%4k62&o^VGMgcaC>_ z*N>P1)u8N1yHK(Pm%iKD3$PuIDFt&|67!)Ox`ggaJWwCaS=*~%8rps>sOQpRCL5hU zbM6f4iccd6@(h&lZyGkA&r6^9Qlc183@8Q^1BwB~fMVdkU|`BB{$drc?^?xNb=$1a zEv-_ns&5?1*O^|x?gqYzZnIwd22Rb+KqL~X=o`n{@_S5w?+Zk?%`)}%Z7$!kN>jTf zv*I($R%BP-Xz53wYDIEoePg75xV{|P(F;!_myk=LiZ6t`AN7q+fBp{^)IZz`F6VaM zH+ODodV%(4wGlhFS_+l(x3v9Sy>LvTP&JlzSCn}gv65NNZ)!!eTuU?>4b&pMO6?px zYul_Nh3;Oza%Z(!1Rwcd1J=saJ!>Ubwo0wzct5mCjIg)O`}WAz8w3D+^nYfX)zaZl zVHHCdH~I;zbylS}UZ5ayy<9YZu72>i zmj}dU@a!u?!)##iEPIKh9os%*)ac2yXBYS^c5Jr85TJ4NPE1Qg;%=!D+Vc*eB@JQ! zMnX2dLw91NUyP>cz9BrLQ_&z=#%!lJiHb~zv zd~B^7m-Q1g7P8j8N?~!9r)%~JAbkUQ5~{;+&izkHe;wz6)c-6LEtx`wadrC>9)Hr~ u(>D|P#zp7LkRT2b#dj2n88}rwI3K=0A1>z8M695vDPmLYaCLxf+~+R{0-cor literal 0 HcmV?d00001 diff --git a/c_piscine_c_03/ex04/t_main.c b/c_piscine_c_03/ex04/t_main.c new file mode 100644 index 0000000..561e4a3 --- /dev/null +++ b/c_piscine_c_03/ex04/t_main.c @@ -0,0 +1,14 @@ +#include + +char *ft_strstr(char *str, char *to_find); + +int main(void) +{ + char str[] = "012340123456789"; + char to_find[] = "456"; + + printf("-----\nstr = %s\nto_find = %s\n", str, to_find); + printf("%s\n", ft_strstr(str, to_find)); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex05/ft_strlcat.c b/c_piscine_c_03/ex05/ft_strlcat.c new file mode 100644 index 0000000..7c260a5 --- /dev/null +++ b/c_piscine_c_03/ex05/ft_strlcat.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuchill +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/12/04 21:44:39 by apuchill #+# #+# */ +/* Updated: 2019/12/05 00:03:33 by apuchill ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_strlen(char *str) +{ + unsigned int counter; + + counter = 0; + while (*str != '\0') + { + counter++; + str++; + } + return (counter); +} + +unsigned int ft_strlcat(char *dest, char *src, unsigned int size) +{ + unsigned int c; + unsigned int d; + + if (size <= ft_strlen(dest)) + return (size + ft_strlen(src)); + c = ft_strlen(dest); + d = 0; + while (src[d] != '\0' && c + 1 < size) + { + dest[c] = src[d]; + c++; + d++; + } + dest[c] = '\0'; + return (ft_strlen(dest) + ft_strlen(&src[d])); +} diff --git a/c_piscine_c_03/ex05/t_a.out b/c_piscine_c_03/ex05/t_a.out new file mode 100755 index 0000000000000000000000000000000000000000..0290bb9884f6866aac18b5181089efead50431cd GIT binary patch literal 8652 zcmeHNT}T{P6uuL+5lyliD6LH`Y^4?x8jaSZO0leIhECdSY7-YiOStZzx@28te_DMI zgjMQf5SI3#^rcUI=tC)aXrSpss)@u_gh(T)1s}Fx%Ph3ugOsfV?RRGG=^PcXvxPc9!4>6*HSSc(ko5T zd{(jvyUKYwlMSbLP0o1r0EFTl5uv-o1k#r^%PYwu!GhS50yD0pm+o>#9I5^KHKZ+-# zJf7?yHuUoO{Z_=IHAFU?uUZ5k-5Jk5FPtYr|Ce8#h=;}? z((UoA??Sk3-|2<(7vGW3o$nPMp944OL`w#kj8PmR8ukYK9XLgjk1?vH8f^z!i~K%( z$4~~*(wq`Tb>Q!yQ~%x<85>1g3+@5iiR!o5Znw)F7*9Dl=?DxyFnxzD*>tKU5f8US z#}ZNKM9+gMkI(9tZ@%(6~5xutqOg^ev+FC~`(q1me=ki!O6B}wi+l;*8VRQn$45s)ud?r4}g-&?6soMK(Z)B_;Hv%wbqua{-tl}~Z$u-HuF5O= zBzXcW(wrK2RJ>`td3-}p!m7%J1$hk?);c>qr)WW4lh@RHp4*jexe}WWJn&4?9$k|Q z$n14_-Sf#DjMwD{UrC-R`sq|`#RG-tT3}6G^j~lHLfOy)1t`<)UI?f|4HV!ugtg+Q zcVuOZ!F z`Um8j$s+uCK?^Rc@{jt5lq%ka{IuW_x_)VPrJb#!oqpEH;0&rNDV^J@JnxyJy=&{N znY>P$Lr-mfr}1wHJB=kgFU-8~E1K@hJB>e~%@5+iihls8LD~`)*C3Ipwe3}E%BcPH znb$fxPqC9kHPKi)zT{F106goOKu^dKBuR`190**dv)YcXW{PjG^Ps zQQZGG2;KUBfRjR}dp+t;r!;7H&p>2{e#N2pIdok98UK?Y?kfFs&}P|uxNY8FCl_^6 bRhEn@xlwf)_y&Y!7IQi*Jon8A-c9r`is|)Z literal 0 HcmV?d00001 diff --git a/c_piscine_c_03/ex05/t_amain.c b/c_piscine_c_03/ex05/t_amain.c new file mode 100644 index 0000000..d2eb902 --- /dev/null +++ b/c_piscine_c_03/ex05/t_amain.c @@ -0,0 +1,17 @@ +#include + +unsigned int ft_strlcat(char *dest, char *src, unsigned int size); + +int main(void) +{ + char dest[20] = "123"; + char src[] = "4567890"; + unsigned int size = 6; + unsigned int result; + + printf("-----\ndest = %s\nsrc = %s\nnb = %d\n\n", dest, src, size); + result = ft_strlcat(dest, src, size); + printf("dest (cat) = %s\nresult = %d\n-----\n", dest, result); + + return (0); +} \ No newline at end of file diff --git a/c_piscine_c_03/ex05/t_main b/c_piscine_c_03/ex05/t_main new file mode 100644 index 0000000..76d1430 --- /dev/null +++ b/c_piscine_c_03/ex05/t_main @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: galves-d +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/29 05:09:22 by galves-d #+# #+# */ +/* Updated: 2019/12/03 03:45:50 by galves-d ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +unsigned int ft_strlcat(char *dest, char *src, unsigned int size); + +int main() +{ + char str0[50]; + char str1[50]; + char str2[] = "Concatenando 1"; + unsigned int tamanho1; + unsigned int tamanho2; + + str0[0] = 'O'; + str0[1] = 'l'; + str0[2] = 'a'; + str0[3] = '\0'; + + str1[0] = 'O'; + str1[1] = 'l'; + str1[2] = 'a'; + str1[3] = '\0'; + + tamanho1 = ft_strlcat(str0, str2, 0); + tamanho2 = strlcat(str1, str2, 0); + printf("String final: %s, Tamanho: %d", str0, tamanho1); + printf("\nString final: %s, Tamanho: %d", str1, tamanho2); +}