From be438f7decf88cdf98687df6327e524f7d765cae Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Tue, 4 Oct 2022 14:21:55 +0200 Subject: [PATCH] v2 --- Makefile | 60 ++++++++++++++----- ft_atoi.c | 10 ++-- ft_calloc.c | 8 +-- ft_isprint.c | 4 +- ft_itoa.c | 55 ++++++++++++++++++ ft_memccpy.c => ft_lstadd_back.c | 24 ++++---- ft_lstadd_back.o | Bin 0 -> 1600 bytes ft_lstadd_front.c | 21 +++++++ ft_lstadd_front.o | Bin 0 -> 1432 bytes ft_lstclear.c | 27 +++++++++ ft_lstclear.o | Bin 0 -> 1648 bytes ft_lstdelone.c | 25 ++++++++ ft_lstdelone.o | Bin 0 -> 1624 bytes ft_lstiter.c | 22 +++++++ ft_lstiter.o | Bin 0 -> 1432 bytes ft_lstlast.c | 22 +++++++ ft_lstlast.o | Bin 0 -> 1424 bytes ft_lstmap.c | 13 +++++ ft_lstmap.o | Bin 0 -> 1080 bytes ft_lstnew.c | 25 ++++++++ ft_lstnew.o | Bin 0 -> 1608 bytes ft_lstsize.c | 26 +++++++++ ft_lstsize.o | Bin 0 -> 1416 bytes ft_memcpy.c | 10 ++-- ft_memmove.c | 4 +- ft_putchar_fd.c | 18 ++++++ ft_putendl_fd.c | 21 +++++++ ft_putnbr_fd.c | 34 +++++++++++ ft_putstr_fd.c | 21 +++++++ ft_split.c | 96 +++++++++++++++++++++++++++++++ ft_strchr.c | 6 +- ft_strdup.c | 14 ++--- ft_striteri.c | 25 ++++++++ ft_strjoin.c | 38 ++++++++++++ ft_strlcat.c | 27 +++------ ft_strlcpy.c | 13 ++--- ft_strmapi.c | 33 +++++++++++ ft_strncmp.c | 8 ++- ft_strndup.c | 31 ++++++++++ ft_strstr.c => ft_strnstr.c | 32 ++++++----- ft_strrchr.c | 18 +++--- ft_strteri.c | 15 +++++ ft_strtrim.c | 44 ++++++++++++++ ft_substr.c | 31 ++++++++++ ft_tolower.c | 10 ++-- ft_toupper.c | 6 +- libft.h | 37 +++++++++++- main.c | 30 ++++++++++ 48 files changed, 848 insertions(+), 116 deletions(-) create mode 100644 ft_itoa.c rename ft_memccpy.c => ft_lstadd_back.c (63%) create mode 100644 ft_lstadd_back.o create mode 100644 ft_lstadd_front.c create mode 100644 ft_lstadd_front.o create mode 100644 ft_lstclear.c create mode 100644 ft_lstclear.o create mode 100644 ft_lstdelone.c create mode 100644 ft_lstdelone.o create mode 100644 ft_lstiter.c create mode 100644 ft_lstiter.o create mode 100644 ft_lstlast.c create mode 100644 ft_lstlast.o create mode 100644 ft_lstmap.c create mode 100644 ft_lstmap.o create mode 100644 ft_lstnew.c create mode 100644 ft_lstnew.o create mode 100644 ft_lstsize.c create mode 100644 ft_lstsize.o create mode 100644 ft_putchar_fd.c create mode 100644 ft_putendl_fd.c create mode 100644 ft_putnbr_fd.c create mode 100644 ft_putstr_fd.c create mode 100644 ft_split.c create mode 100644 ft_striteri.c create mode 100644 ft_strjoin.c create mode 100644 ft_strmapi.c create mode 100644 ft_strndup.c rename ft_strstr.c => ft_strnstr.c (61%) create mode 100644 ft_strteri.c create mode 100644 ft_strtrim.c create mode 100644 ft_substr.c create mode 100644 main.c diff --git a/Makefile b/Makefile index 7a9f0b0..13e97f4 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: cchauvet next = new; } diff --git a/ft_lstadd_back.o b/ft_lstadd_back.o new file mode 100644 index 0000000000000000000000000000000000000000..cc1d98b14976c5ac1e0d56cdd194c687408fb0e2 GIT binary patch literal 1600 zcmbtTPixdr5T9&nTea0~@gUScIf;UO?AjvQL)mu8Zji-_c8?O1-PD4c-IBbOt)LzR zA@s7J!IK|D@SuK+UW7e(5icS_ok`wwvoXEsz+`5AncvLh&C6@EQ7dQ~uxPLjbzqLH1F)h`Bg(WQ^Cv>6%|k1CFgyJ6 z5$e_InsL49_Perg+!d>$v|R4TQTf%ak|?c;@{I(KdjU+LEux-6t>14#0pJ5+Jk|yD zNwgOaK^qjcrMa2eA%4gu#7IeQ)5APhd|Rl_Py3ia@d-j_Fa_U_@?PutCxo-`G?Oen zo_-ReNQdda!5E)80neXUk56TivWVegYR>rE5xa~^=a`ih1oCj$k#;APPP=WpPV1Ry zDS!g7>y53=jfTBdt35Ke?d^@thH0yWjuT3(c~v!{U7bb!eUylyaNHy9ax5a;_od^4 z2xXAiUG@U6;|S>uB#5>n9T099f@t-8-|HgQ?MYAI-B`wPakwOY+U<+Iptt7*avwxo z!P~WW0>}5pJ^#ZqkV|(ZyU7Y-Bz*2kl;pBcb_tcvrh=N5C+bixD)0ccmH@oNgt z-n{3Emo-!)EjKZsn*Yi#BbREHP}9QwseW3xKif5Y$$mQTT{=kl+1z{hj{cU3JB0Cj z#W9p+!{^7biw@Py@;|GDJDjL&mj4*>y!{PSLEaPXkGRZdJg;}$N`0uIEd4vDbNGa1 ecSn3f^next = *lst; + *lst = new; +} diff --git a/ft_lstadd_front.o b/ft_lstadd_front.o new file mode 100644 index 0000000000000000000000000000000000000000..3e30764a60f787e0c0da3435ed61acc0c263d8fc GIT binary patch literal 1432 zcmbtT&r94;5T0zT+SY2+9t5Rq>7f<$krgfKp)4$0b0|fGgw0MiUcQ-c=6i46kG!wHdRek8P-ejkxQP@C z@Tqj;S97-tV{jiXCmvllyzURLdv@h@)6DyDmVun}&g)m+xr2~--ObS=Y@qM_v@W*4 z!A7mNUVheSrjbm`YhqcriKJJ2*C8HvrrDN}P>@>|p_5 zz1;%q#Ia__Mn*4iBXh{pAbU=q`ndD4RC_QSVgbds7@ffo{Q5m8Z4W#l>P0&wO=$PJ z)JSygd^i0ZMK%ooP3HW_Ej*n>zfEH}rS+Nbol17)&S4_`c6(I$FBS^;Kly~W>HIbXr5%1=j@#a$L5=Vj68AbeQ_BaE5|@n{}l7|zW!Ce zfLfZ<#i5&8pYpn?^%bsQQu%t_XFbq-v$l>odTo7okMS4Qlo=J6|I#)lXiiiAodv5( z$Y|={AWyHl%6SDdJmCxzcM+*irC0o*wQ~t?G-LfeM4H3Y6KCEXNix=X0B~wD literal 0 HcmV?d00001 diff --git a/ft_lstclear.c b/ft_lstclear.c new file mode 100644 index 0000000..6d07272 --- /dev/null +++ b/ft_lstclear.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet next; + ft_lstdelone(*lst, del); + *lst = next; + } +} diff --git a/ft_lstclear.o b/ft_lstclear.o new file mode 100644 index 0000000000000000000000000000000000000000..2114b9eb0613743510093db494a4ef791a33bab6 GIT binary patch literal 1648 zcmbVL&ubG=5S~qHTeY=OJO~xplPK87Mtaa5%C=#XhXgCy+>~XLZY`J}W%mVIp?W9^ zOD_2*1pkbHf_U^I9&-@_^&(z^2z6%jUb1ZF$_>*z&cDK zg#uXFiEqcQ4U4bOk=;{X;MYAS`~v}O#}gi~Y8V2mwHgh- ziCD8Ge1>mhB@|xmg^Zs!+iX8*?fZc^1Qze$@435y*H9gqls=1RB8lFLK1mxf61|H4 zFVZ}yH#TZgy0R(PBzOTWan%b@_)UrHFYle?=|-=ANA7u6KD`^-)6xp5`m}#iRDEUF za8dcmyf4Wh;p@2%aE<content != NULL) + del(lst->content); + free(lst); + } +} diff --git a/ft_lstdelone.o b/ft_lstdelone.o new file mode 100644 index 0000000000000000000000000000000000000000..e5dbd56f9889dc3347e20288798fc913d5f9923f GIT binary patch literal 1624 zcmbtTPiqrV5T8wI>z`Jmcqmk5PoiiaS?!_rAZbIAMN$jec#~z5zF07S%I*uKLiJD- zLM}P^8T=SU57n#RK`7{<;w6X>XLjF^&APqVfyvDL-uunW&b+)Sl#40D02Tut!Z>0S zU_L$ebAg+KIhciCmu~#7*u8J|{*R2^+Z)=w&au6}Hw3jD8Y?t+?0#Wr_rZR9pfc?D zE5~;4aP&2ZdxuAq_q#Fp@(D`${EB(2Qth-<$9y1`M0U~Y1d;XnURGq6gmpW_gI)lp z&}LB2pq3t2AO&zh7`J^DeG=o<6EM0NV_|mY>;OOX8e*g*&*-OcG4n2!pPNpt;|&6m zg=RDbKSxQY>BI?AFWk)}D;;z{iBXh>>3_ihpE&_fZa5uGWs*X(x)SL#_;$puqtaPi z?jw+dLtQxyUv0@oyCp?!A_S*Y-dI~LI~&E~)54~+xw=*^I8gVbgmqnjc60&t&nOgA zBjI_6QFxbqvJ0p*n;dFXx_T({ z8a$7d>hR_nzp3%~i+itmaYH$xau);2`M-P%xs)@D8WpZj`J=-1*{rsLl}S798+61JU@=B=upl$|43h0=8M|K`Ogtg+TTDYnext == NULL) + { + f(lst); + lst = lst->next; + } +} diff --git a/ft_lstiter.o b/ft_lstiter.o new file mode 100644 index 0000000000000000000000000000000000000000..6ee55e66757662f01114e5945bbfef4491d0180c GIT binary patch literal 1432 zcmbVL&ubG=5T4D}Hfn9t(nCv&#FGm4u_+a_2U!TQdk_yoz>Abk+_qwql-;+q6|99) zVd*7D|A-#?Clox0H}UA*Q$0ky1TS@F_f7KhOfMano%z0b-+S|Z?1##;r#Z_4HVd9W zA2AE?Dc8^4G<9JdZo;3*+kdNG^3yx~Rq&GcT`!3{=X2h1rRyD6J6`hT;(G?%yq6G3 zj``7<{LyZI{S2$+@=EbuwH7yJTzo8+g|k?SQ&ieta)h%iO7}B9U3CP%1@vp^tIw-| zZJiNkqm#{K0jzf~z}hWX^W$UrHg0GEd2%wBK9z~W$6Wc==nf7be2LLnjKJ@UVP$*h zNl`D_VQE6U*QG{cYNxvyWrXar5UgDqbKn``T#-w3#itH*hi(%qRS=&C6>DyW@M#@xX`dVW_t?tl{`(pcT@ zBA|D5Rs93h(wq*uZU+ibT{m8z<3lWRu8%v>ftH(ND_EmfHgNZdPnD*qA_wyydW8j= z)6{=cf=4V=(bT_0o?f%7>Kta(gtLmcj*WMS&4k_p= Z{Tunext != NULL) + lst = lst->next; + return (lst); +} diff --git a/ft_lstlast.o b/ft_lstlast.o new file mode 100644 index 0000000000000000000000000000000000000000..263df5dcf8d3a5d78a6ae28962079e6a4ba3c7f5 GIT binary patch literal 1424 zcmbVLPfHt75TDJe(P}kX4=qtiPgQ6hNl~ahl!cJG2k{^TyohYl)j;!)-M5ew)I(_@ zc=1aV`Vo2*dg&J_J@k^&OXx*sHuK`kGhQ5+%*=1*H#_s*%XxA4UBa?Ji3M-rHc}|S zW#ZO%V%LE=n1z1}YyV4b_m|r}?Yo~&`w%_(PU%0Z?nSZhUO3Zkmn{3AucF@+9R7fv zLg7tjy;P1GGRka=O_9syqd3Z+y~>H)rpRv$aOyXKnnImK-PtPvj&ntrjY_gSFkpS$ z2dka3(sRk_OI&0HaZ-|P`YFz*z9b5dr&?G*@jXIkFadwB$EEGDCq%Poholkh;glMP zt{rbPicw_4)Lk&fllS0s5~DJY;gU9IygQW~%cEK-YhEZtMGF)=!wzjSvW*Bkb?KEs zgfbY|s`8}YmLT4H(gRTrLlBi_z3w*KaGORd-JN-Y4!0bh1IOlDe~vg|>RoXebd+OQlm7zq^sXMte~Db`nM2h@ zeV_8WsP8Mgg-PY>bzk*B^Uc~K=IE7;+&#wMn3G|vjQJlr#02#;`9GQPS`pcr`~$@4 zH9MSFCdCb(GBAUd=2U!zkNb8^;YEAQe}tBLn0&&_yCX`E`OhfOgyA8wh~7BS5T11FF9>=Qyu_0Vc1ffj^dNy!dlB(c@FJ4Ls9^I$vH^Rkui)c&>?`>M zI+O0=vYUG7!0haN^L?|EP4Y3kx$Za)D0AQn{xXFEd}(0NzyWN-7QkpQxO9)lQJsm} zz2JTB_58ZY{Mnhuy*~F(7I>rT;<}5zhCaF-LkD0^7(@Th==d&t|Fm&f>%`O(ySEry zavE!(Esy{_7_4Lqn3uHod-PHLio?}t%b>2izw7tn4Vr>K6{K5*Uab;A2o>e#MXKJbb rDM@n~NvE8keTn0rXWbo@?&P35lBa?>{~i|1yC?30B;G5bjHdnnext = NULL; + new->content = content; + return (new); +} diff --git a/ft_lstnew.o b/ft_lstnew.o new file mode 100644 index 0000000000000000000000000000000000000000..790a09e3c083931c2c8e13498d98004346e367d5 GIT binary patch literal 1608 zcmbtUL5tH+5S}#aw(3@^hzb?SNfhiOl^%2tlHHOvN^wEAM+s>+Yr(W#k{8?+R)qzj z?8T#hMDV8ILHq~)0imE5@v?}p&b++0O=G<1z;tH5H{Z<5Ow#9er&Z82P@=(Ym_-T& zDCslb60QYhSb`s?FaPX1lP}KRH^Z6iPTy7Va7qcz#6EELb`KyfzNPqU)!9enqg4{8 zHkXa7-CjK6v2lwvm|3gGBC0>TVKTG9>emvS_zS4i>KJPKUKa`g z?+H`aJcmAs_Vhkz+ZC<4R4l#12fKtADajrBu}@WA7MkV7f`u6bivf8m-7c{m~9*!lIoa z_jyL*+e}vd*%zcLML@nZ8|FMi8jbgSHj<@`f z?*J1O{DHd}dP9HK^FKTTx%7@?H)tV7qUN1MNv`tAR#9m-7HV1sawr!icmgf;QJYuz z6^UoxxQXOt4b@1?bquKHzw+zIrJ5#cT2z0kpBB|$*=0Obemd_>I!O81+`D*2U&-7% zgt7SRL2IC4d{9GL`gV@z h@CnQA4k0jQ{{{sqk>!q%Gw9{next; + } + return (count); +} diff --git a/ft_lstsize.o b/ft_lstsize.o new file mode 100644 index 0000000000000000000000000000000000000000..87640c3359c69c8213c6ddfe51116d296cd3a9da GIT binary patch literal 1416 zcmbVLPfHt75TDKZCvB~b#Y2mwY)@9uMsgk~v)oF8Q?n`54C*xM)^-taj5ESaRFcKSfYJE~ zMk`}1&CRBN;09hGPD+xa#hK51OBEi^)Ubf!JB0Q=1s6Ay(&ogIp;?r}QHbVnN(DsM zjCV7RQDnl*Z7{}X@4)FK#$_JEr^=l1-l=4lmk&Z7?st4vRRYPjghM+S+YJlbb?#Mw zg*-@XO?upKabPF)Fsv_;F|Ifz()h{dJ+r8) z$nR5L75RN>H!vxEweF`HD863nV2)nd*xh4%ib`U|>uAycp%SL3r_MhUlsCdkqw_yu zf?l&N3xrLJhR;O&04>ca`4XS>ZK7P!g7Pmh@DMHa(D{VvcSn@IIH>0oC?en?vVh(s Oz9r`08&)Qc&i@Z2Q)EH_ literal 0 HcmV?d00001 diff --git a/ft_memcpy.c b/ft_memcpy.c index 1467ba9..ff412ad 100644 --- a/ft_memcpy.c +++ b/ft_memcpy.c @@ -6,7 +6,7 @@ /* By: cchauvet 9) + { + ft_putnbr_fd(n / 10, fd); + ft_putnbr_fd(n % 10, fd); + } + else + ft_putchar_fd(n + 48, fd); +} diff --git a/ft_putstr_fd.c b/ft_putstr_fd.c new file mode 100644 index 0000000..d8c87d2 --- /dev/null +++ b/ft_putstr_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet max) - max = ft_strlen(str); - if (ft_strlen(dst) > max) - max = ft_strlen(dst); - i = 0; - while (i < max) - { - dst[i] = str[i]; - i++; - } - return (dst); + if (size == 0) + return (ft_strlen(src)); + len_dest = ft_strlen(dest); + if (len_dest >= size) + return (ft_strlen(src) + (size)); + return (len_dest + ft_strlcpy(dest + len_dest, src, size - len_dest)); } diff --git a/ft_strlcpy.c b/ft_strlcpy.c index c29d03d..677264b 100644 --- a/ft_strlcpy.c +++ b/ft_strlcpy.c @@ -6,24 +6,23 @@ /* By: cchauvet 0 || s[i] == c) { - if (*s == (char) c) - ret = (char *) s; - s++; + if (s[i] == c) + return ((char *) &s[i]); + i--; } - return (ret); + return (NULL); } diff --git a/ft_strteri.c b/ft_strteri.c new file mode 100644 index 0000000..c202588 --- /dev/null +++ b/ft_strteri.c @@ -0,0 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet len) + max = len; + if (start >= ft_strlen(s)) + return (ft_strdup("")); + sub = ft_strndup(s + start, max); + if (sub == NULL) + return (NULL); + return (sub); +} diff --git a/ft_tolower.c b/ft_tolower.c index 642fee9..14d83da 100644 --- a/ft_tolower.c +++ b/ft_tolower.c @@ -5,16 +5,14 @@ /* +:+ +:+ +:+ */ /* By: cchauvet = 'A' && 'Z' >= c) - return (c - 48); - return (c); + return (c - ('A' - 'a') * (c >= 'A' && 'Z' >= c)); } diff --git a/ft_toupper.c b/ft_toupper.c index 6fda229..3775f6d 100644 --- a/ft_toupper.c +++ b/ft_toupper.c @@ -6,7 +6,7 @@ /* By: cchauvet = 'a' && 'z' >= c) - return (c - 48); - return (c); + return (c + ('A' - 'a') * (c >= 'a' && 'z' >= c)); } diff --git a/libft.h b/libft.h index 9ae182c..39b4339 100644 --- a/libft.h +++ b/libft.h @@ -6,22 +6,30 @@ /* By: cchauvet # include +# include +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +char *ft_strdup(const char *s); +char *ft_strndup(const char *s, size_t n); +void *ft_calloc(size_t nmemb, size_t size); int ft_isalpha(int c); int ft_isdigit(int c); int ft_isalnum(int c); int ft_isascii(int c); int ft_isprint(int c); size_t ft_strlen(const char *s); -/* todo */ void *ft_memset(void *s, int c, size_t n); void ft_bzero(void *s, size_t n); void *ft_memcpy(void *dest, const void *src, size_t n); @@ -34,8 +42,31 @@ char *ft_strchr(const char *s, int c); char *ft_strrchr(const char *s, int c); int ft_strncmp(const char *s1, const char *s2, size_t n); void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); void *ft_memrchr(const void *s, int c, size_t n); char *ft_strnstr(const char *big, const char *little, size_t len); int ft_atoi(const char *nptr); +char *ft_substr(const char *s, unsigned int start, size_t len); +char *ft_strjoin(const char *s1, const char *s2); +char *ft_strtrim(const char *s1, const char *set); +char *ft_itoa(int n); +char **ft_split(const char *s, char c); +char *ft_strmapi(const char *s, char (*f)(unsigned int, char)); +void ft_striteri(char *s, void (*f)(unsigned int, char*)); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int f); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); + +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **lst, t_list *new); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lstadd_back(t_list **lst, t_list *new); +void ft_lstdelone(t_list *lst, void (*del)(void *)); +void ft_lstclear(t_list **lst, void (*del)(void *)); +void ft_lstiter(t_list *lst, void (*f)(void *)); +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); + #endif diff --git a/main.c b/main.c new file mode 100644 index 0000000..c652ae1 --- /dev/null +++ b/main.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet +#include "libft.h" + +int main(int argc, char **argv) +{ + char **splitted; + + if (argc < 2) + return (1); + splitted = ft_split(argv[1], argv[2][0]); + while (*splitted != NULL) + { + puts(*splitted); + free(*splitted); + splitted++; + } + return (0); +}