From 8c0603454f8db969d272c1522a9df1c6d25f5271 Mon Sep 17 00:00:00 2001 From: Lahsen El Bouhali Date: Mon, 17 Sep 2018 03:36:52 +0100 Subject: [PATCH] Add files via upload --- with_mains_day10/ex00/Makefile | 35 +++++++++ with_mains_day10/ex00/includes/libft.h | 22 ++++++ with_mains_day10/ex00/srcs/ft_putchar.c | 18 +++++ with_mains_day10/ex00/srcs/ft_putstr.c | 22 ++++++ with_mains_day10/ex00/srcs/ft_strcmp.c | 26 +++++++ with_mains_day10/ex00/srcs/ft_strlen.c | 24 +++++++ with_mains_day10/ex00/srcs/ft_swap.c | 21 ++++++ with_mains_day10/ex01/a.out | Bin 0 -> 8844 bytes with_mains_day10/ex01/ft_foreach.c | 23 ++++++ with_mains_day10/ex01/main.c | 76 ++++++++++++++++++++ with_mains_day10/ex02/a.out | Bin 0 -> 8692 bytes with_mains_day10/ex02/ft_map.c | 28 ++++++++ with_mains_day10/ex02/main.c | 39 ++++++++++ with_mains_day10/ex03/a.out | Bin 0 -> 8560 bytes with_mains_day10/ex03/ft_any.c | 25 +++++++ with_mains_day10/ex03/main.c | 54 ++++++++++++++ with_mains_day10/ex04/a.out | Bin 0 -> 8520 bytes with_mains_day10/ex04/ft_count_if.c | 27 +++++++ with_mains_day10/ex04/main.c | 44 ++++++++++++ with_mains_day10/ex05/a.out | Bin 0 -> 8652 bytes with_mains_day10/ex05/ft_is_sort.c | 27 +++++++ with_mains_day10/ex05/main.c | 39 ++++++++++ with_mains_day10/ex06/Makefile | 13 ++++ with_mains_day10/ex06/do-op | Bin 0 -> 9188 bytes with_mains_day10/ex06/includes/ft.h | 28 ++++++++ with_mains_day10/ex06/srcs/fonctions.c | 92 ++++++++++++++++++++++++ with_mains_day10/ex06/srcs/main.c | 83 +++++++++++++++++++++ with_mains_day10/ex06/srcs/operations.c | 38 ++++++++++ with_mains_day10/ex07/a.out | Bin 0 -> 8568 bytes with_mains_day10/ex07/ft_sort_wordtab.c | 57 +++++++++++++++ with_mains_day10/ex07/main.c | 46 ++++++++++++ with_mains_day10/ex08/main.c | 28 ++++++++ with_mains_day10/ex09/main.c | 28 ++++++++ 33 files changed, 963 insertions(+) create mode 100644 with_mains_day10/ex00/Makefile create mode 100644 with_mains_day10/ex00/includes/libft.h create mode 100644 with_mains_day10/ex00/srcs/ft_putchar.c create mode 100644 with_mains_day10/ex00/srcs/ft_putstr.c create mode 100644 with_mains_day10/ex00/srcs/ft_strcmp.c create mode 100644 with_mains_day10/ex00/srcs/ft_strlen.c create mode 100644 with_mains_day10/ex00/srcs/ft_swap.c create mode 100644 with_mains_day10/ex01/a.out create mode 100644 with_mains_day10/ex01/ft_foreach.c create mode 100644 with_mains_day10/ex01/main.c create mode 100644 with_mains_day10/ex02/a.out create mode 100644 with_mains_day10/ex02/ft_map.c create mode 100644 with_mains_day10/ex02/main.c create mode 100644 with_mains_day10/ex03/a.out create mode 100644 with_mains_day10/ex03/ft_any.c create mode 100644 with_mains_day10/ex03/main.c create mode 100644 with_mains_day10/ex04/a.out create mode 100644 with_mains_day10/ex04/ft_count_if.c create mode 100644 with_mains_day10/ex04/main.c create mode 100644 with_mains_day10/ex05/a.out create mode 100644 with_mains_day10/ex05/ft_is_sort.c create mode 100644 with_mains_day10/ex05/main.c create mode 100644 with_mains_day10/ex06/Makefile create mode 100644 with_mains_day10/ex06/do-op create mode 100644 with_mains_day10/ex06/includes/ft.h create mode 100644 with_mains_day10/ex06/srcs/fonctions.c create mode 100644 with_mains_day10/ex06/srcs/main.c create mode 100644 with_mains_day10/ex06/srcs/operations.c create mode 100644 with_mains_day10/ex07/a.out create mode 100644 with_mains_day10/ex07/ft_sort_wordtab.c create mode 100644 with_mains_day10/ex07/main.c create mode 100644 with_mains_day10/ex08/main.c create mode 100644 with_mains_day10/ex09/main.c diff --git a/with_mains_day10/ex00/Makefile b/with_mains_day10/ex00/Makefile new file mode 100644 index 0000000..46f15f4 --- /dev/null +++ b/with_mains_day10/ex00/Makefile @@ -0,0 +1,35 @@ +## +## lahsen El bouhali +## + +NAME = libft.a +INC = ./includes/ +SRC = ./srcs/ +SRCS = $(SRC)ft_putchar.c $(SRC)ft_putstr.c \ + $(SRC)ft_strcmp.c $(SRC)ft_strlen.c \ + $(SRC)ft_swap.c +OBJ = ft_putchar.o ft_putstr.o ft_strcmp.o ft_strlen.o ft_swap.o +RMOBJ = @-rm -f ./*.o +RMLIB = @-rm -f ./libft.a +AR = @ar -rv +CC = gcc +CFLAG = -Wall -Werror -Wextra +OPTION = -c -I$(INC)*.h + +all: $(NAME) + +$(NAME): + $(CC) $(CFLAG) $(OPTION) $(SRCS) + ar rc $(NAME) $(OBJ) + +clean: + $(RMOBJ) + +fclean: + $(RMOBJ) + $(RMLIB) + +re: + $(RMOBJ) + $(RMLIB) + make diff --git a/with_mains_day10/ex00/includes/libft.h b/with_mains_day10/ex00/includes/libft.h new file mode 100644 index 0000000..24177f2 --- /dev/null +++ b/with_mains_day10/ex00/includes/libft.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +void ft_putchar(char c); +void ft_putstr(char *str); +int ft_strcmp(char *s1, char *s2); +int ft_strlen(char *str); +void ft_swap(int *a, int *b); + +#endif diff --git a/with_mains_day10/ex00/srcs/ft_putchar.c b/with_mains_day10/ex00/srcs/ft_putchar.c new file mode 100644 index 0000000..b16b7b7 --- /dev/null +++ b/with_mains_day10/ex00/srcs/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/with_mains_day10/ex00/srcs/ft_putstr.c b/with_mains_day10/ex00/srcs/ft_putstr.c new file mode 100644 index 0000000..0091548 --- /dev/null +++ b/with_mains_day10/ex00/srcs/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} diff --git a/with_mains_day10/ex00/srcs/ft_strcmp.c b/with_mains_day10/ex00/srcs/ft_strcmp.c new file mode 100644 index 0000000..16ca215 --- /dev/null +++ b/with_mains_day10/ex00/srcs/ft_strcmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + int i; + + i = 0; + while ((s1[i] != '\0') && (s2[i] != '\0')) + { + if (s1[i] == s2[i]) + i++; + else + break ; + } + return (s1[i] - s2[i]); +} diff --git a/with_mains_day10/ex00/srcs/ft_strlen.c b/with_mains_day10/ex00/srcs/ft_strlen.c new file mode 100644 index 0000000..4a6d6c0 --- /dev/null +++ b/with_mains_day10/ex00/srcs/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int len; + + len = 0; + while (*str != '\0') + { + str++; + len++; + } + return (len); +} diff --git a/with_mains_day10/ex00/srcs/ft_swap.c b/with_mains_day10/ex00/srcs/ft_swap.c new file mode 100644 index 0000000..bcb284a --- /dev/null +++ b/with_mains_day10/ex00/srcs/ft_swap.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int *c; + + c = 0; + *c = *a; + *a = *b; + *b = *c; +} diff --git a/with_mains_day10/ex01/a.out b/with_mains_day10/ex01/a.out new file mode 100644 index 0000000000000000000000000000000000000000..e2fe8d467eb8f7da9ed468150295c11fda2d961b GIT binary patch literal 8844 zcmeHNUu+ab7@wo9mP);1(6j+%tyBxzQiutEl;mpIxFCfpZ6s=)+@C$}!u77X+Y4ZF zrh1Tcvs_Y%J{Vv04IfNuqKUr1K}m{+D4Jjz!$TiVvyGZuw1&f+oWE~(u6MTu-;Mhv zGvEB?`{tW(emh(CX8886-)`T_n5T)c$yJOoFUoKWW2c#f7Gqr~3JT}LgU`#a$S)nD z-bV2>!aE|0(~Ai>ACZrYG`d*hI~x0#z{rgu9d?f}bFQf;w3@Fo-ozR#2IjYDF%ZJd zcGIq#*jZLUYI631rgJ8<9Uj!g5 zQnhnOUwv>ZUOIj} z8V~VkJe;s_KJQpv&xn#rank7mO*z7ckh}YqpDqZl<$XvSeB{lS~r{s#c9{+YLx?IGF zj?LMW35t=4Qfjsk+n#f1i@u^9JmS(b7hg z7{p3xPQF1opz}Sl>GA@aXYHnGv`Q6r%2claZcR zg7UmEa(V&IAHiUZ&Sx)q^wD`;zOs0gmXh1k1y7jYhWR{w0xG%8f|6_BLRNj~nqrJz z)8)(NkAGXVk77QaU; zsA`%jg%k0h7EQz@e>fZsMpP-Lrli@AW3%VR)wq_DLTO3!2V$x}E$xJ>(!pn*lsfSEek#UM%e|nh;8J^kU)j>2H{e#@nEgryH7(?q2H<`)TZAKYY?Hs zibB1$hJ_r}I`O;h5utm9cDT9FWx!>?Wx!>?Wx!>?Wx!>?Wx!>?Wx!>?Wx!?NKfu7+ z?#{!M=2{=8t8jnt7!O8{@uO*fGQ?g?vS}Y(vRRkpJb-&%Txw5~f3njtBJ7XGU`k5p zpTLE+7ADjSbUYc=RC^Q#dN}U?n)rBxt0&Z8T2paX?x(Pu!Ww72<9_C+a}2gBoJgwv zV1(_QNNa3Q6D#5@W>qlaPqO{-K$0D5V)-r{YZSXYJcx6aID4&$P2w651MQ<39%iX% zoSkT5Gwb2FKv#r_GCVNt85p283C-p8&^eubAo7rf?Q;}5XXzF=FaBQv-P?O%CXm$R@LlDY+MwBDSG0-aT2oNW$NhEe0)gL#ePiu{h8}w-RkwuL3@i4OmGnPnCsl3$ literal 0 HcmV?d00001 diff --git a/with_mains_day10/ex01/ft_foreach.c b/with_mains_day10/ex01/ft_foreach.c new file mode 100644 index 0000000..410c591 --- /dev/null +++ b/with_mains_day10/ex01/ft_foreach.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_foreach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/12 00:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/12 04:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_foreach(int *tab, int length, void (*f)(int)) +{ + int i; + + i = 0; + while (i < length) + { + f(tab[i]); + i++; + } +} diff --git a/with_mains_day10/ex01/main.c b/with_mains_day10/ex01/main.c new file mode 100644 index 0000000..ce47403 --- /dev/null +++ b/with_mains_day10/ex01/main.c @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/12 04:23:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/12 08:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putnbr(int nbr) +{ + if (nbr < 0) + { + ft_putchar('-'); + nbr = -nbr; + } + if (nbr >= 10) + { + ft_putnbr(nbr / 10); + ft_putchar((nbr % 10) + '0'); + } + else + ft_putchar(nbr + '0'); +} + +void ft_putnbr_clean(int nbr) +{ + ft_putnbr(nbr); + ft_putchar('\n'); +} + +void mafonction_f(int i) +{ + printf("cette fonction affiche les élèments du tableau : %d\n", i); +} + +void ft_foreach(int *tab, int lenght, void (*f)(int)); + +/* déclaration du pointeur sur fonction f = mafonction_f +** Initialisation de la fonction ft_foreach(tab, 5, (f)) +** Appel de la fonction ft_foreach(tab, 5, (f)) +*/ + +int main(void) +{ + int i; + int tab[5] = {0, 1337, 42, +1, -1}; + void (*f)(int); + + printf("tableau d'entiers\n"); + i = 0; + while (i < 5) + { + printf("tab[%d]:%d\n", i, tab[i]); + i++; + } + printf("----------\n"); + f = mafonction_f; + ft_foreach(tab, 5, (f)); + i = 0; + printf("----------\n"); + ft_foreach(tab, 5, &ft_putnbr_clean); + ft_putchar('\n'); + return (0); +} diff --git a/with_mains_day10/ex02/a.out b/with_mains_day10/ex02/a.out new file mode 100644 index 0000000000000000000000000000000000000000..deda5a0207de9eb5179ecd7007136c455f90a52e GIT binary patch literal 8692 zcmeHN-D@LN6u)Ux?S9mBSCq=GIxbu7e$dvkN*C?YEFE`NTQ_c7T$FOnXB#$6LO!qs zD}~yJVFyt0S95}i6ckel8 z&i&m9+}x9I|NQ;0M}_dU3$ffLga|-G9YU-M1wA32f@)AHL&0n6JL=6F9Bma}EBr^q zIDL44lvC=hsa6xyzq@rzSQxnpq$3`&rll;z7Ya>Vcf4{J7K7=VR#L?Nra8f~6H1vc z6eIbAA$Po!AcUb#S{6389XhRe&HNZo&c##Ncn(JHcxSD6{Z;^C@_rzP@{4BD`R0P% z@!qrI+4K>&toI;rqa$TBU&tlXv(~sfUe=1oJ*N;mr6pHPNLft3pG?POGM&hnxOIO& zb;Tog$8g5ydom2dr5p=R1syY3pt+^?LR~H26THKw(o4$OOp~>T$Lpjq1@Y)_3-{BB zrA((}esMmMNy%&>cPPJ3D?d9eVy8djIrl}%RQTWG^;q$Gtb~Z2@wi_5ouf(fdpdso z%{SDs>-Kj{aq$LB*)z!$f^n>_IetcnuM=}B<$n#J>udFoqJ7;0?f&6(d#6==!nIts&8}W=xlB3jK6-`>tAH z?3Ja8KTx_%tJ26PXpCY-i>ei4YPD)iRFLKNIN)oBfBBB61!*u*S=sRE6BS+kZ1;0B zi;iPv7Dxmuzq}P#2>b*P=*L&N{Pd`4#OHbd!L~yd+`#svVIhyVM zigk374Rl0rE0Zf|Tx8Buy;7nNW(n@UE*g=8kJ#NtXS ztRyn&s0kB&3+G@pq?}h4l#!7uiqrEbQxvD66lcq`Du44{LQ8!dzqcstGl%2w>^8kQ z+U%If@o~xe-FC%lHLG=)cwLVHj{%PXj{%PXj{%PXj{%PXj{%PXj{%PXkAeRQ11HY( zOfuCIqmrfYaP+o}&fS)?#c(br-pYx!Q5M%!kDwuQA$18CAVD z`$k00imS=AxYjQ2oW|UCZ<#5bRR910 literal 0 HcmV?d00001 diff --git a/with_mains_day10/ex02/ft_map.c b/with_mains_day10/ex02/ft_map.c new file mode 100644 index 0000000..6d3662b --- /dev/null +++ b/with_mains_day10/ex02/ft_map.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int *ft_map(int *tab, int length, int (*g)(int)) +{ + int *tmp; + int i; + + i = 0; + tmp = (int*)malloc(sizeof(int) * length); + while (i < length) + { + tmp[i] = g(tab[i]); + i++; + } + return (tmp); +} diff --git a/with_mains_day10/ex02/main.c b/with_mains_day10/ex02/main.c new file mode 100644 index 0000000..a301188 --- /dev/null +++ b/with_mains_day10/ex02/main.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +//#include + +int mafonction_g(int i) +{ + return (2 * i); +} + +int *ft_map(int *tab, int length, int (*g)(int)); + +int main(void) +{ + int tab[4] = {1,2,3,4}; + int *dTab; + int k; + int (*g)(int); /*déclaration du pointeur sur fonction pour g*/ + + g = mafonction_g; /*Initialisation pour g*/ + dTab = ft_map(tab, 4, (*g)); /*Appel g*/ + k = 0; + while (k < 4) + { + printf("tab[%d] = %d, Application de la fonction f(x) = 2 * x ==> tab[%d] = %d\n", k, tab[k], k, dTab[k]); + k++; + } + return(0); +} diff --git a/with_mains_day10/ex03/a.out b/with_mains_day10/ex03/a.out new file mode 100644 index 0000000000000000000000000000000000000000..774cd5e0545887915212386f5168195a53a2dca6 GIT binary patch literal 8560 zcmeHML2MgE6#Y(Ih)Ro{1E>%JOVv~bq$Y);R*;e*}Bi9+2(OI<`10k4FKZjgo+(KBEJEX0-gJNgIu`|q)}okH#E zKWZH39y$s!p-)Y;ck#wY+ifIu)ghM?hd-%FPphw2@{jGRn*38bEd35TGmy+?Gl>u01-1q1}elrC- zpRqoc9XjJ(m+^+ApYp7Zqf{aBIlc+Z(w?~Kv%w4S`LHLwt) z@riiAgZ=Ziz~9#n$@_|TZZEbFR#p@ia>==@n78x)8qW{I?+1_fiSd_P?wN$hCLR?p zit*gPM+RU$7|+j7x&z)4A#Q;<)9uYiN(e^}uwEXw$`b^L z=Q$5%ALko>wTiSt`*UOd@r8nI=1#wL8hK=r=ma_m=J}Sj7Je^Do$*nm5Kssx1QY@a z0fm4<;Qxrgq~ZKwlr}ZPS!@_iu~yNm41?k74P$1kYLtd=Q{>avTc(=fj=?-xHQeD} zo9m_RP~-;xm{s(h5JdecJY2n6S`9gRwf4%UrwpITfVO)J{dM)z8D3Q!J>gDS$HfmqPeIOD3^KF|t zI=z+-jvtaQ3u*(>2&oK{8OVBzW;Z|d8T@+)W?<&oE}*}oZ@R@z4CY_lGk-byU8ezb zhJa3U;2YR3m-}x*#K)ThWys}OJgELBLJkxT)7!I&wQns`OU+rfmQ84OB9qOUnpv>5 zGuj0$ZHt7ppuM3Dr0|FBoh6>*@t~mOe`r4Io`q!Qb1D8(2szMFbp>M>lpu+DYB2pUULKPPprJF(KgMkh73hO&6s_AB VVkws +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_any(char **tab, int (*f)(char*)) +{ + int i; + + i = 0; + while (tab[i] != '\0') + { + if (f(tab[i]) == 1) + return (1); + i++; + } + return (0); +} diff --git a/with_mains_day10/ex03/main.c b/with_mains_day10/ex03/main.c new file mode 100644 index 0000000..4bcd44b --- /dev/null +++ b/with_mains_day10/ex03/main.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_any(char **tab, int (*f)(char*)); + +int ft_strlen(char *str) +{ + int len; + + len = 0; + while (*str) + { + str++; + len++; + } + return (len); +} + +int mafonction_f(char *str) +{ + if (ft_strlen(str) == 1) + return (1); + return (0); +} + +int main(int argc, char **argv) +{ + int reponse_ft_any; + int (*f)(char*); + int i; + + argv[argc] = NULL; + i = 0; + while (i < argc) + { + printf("%s\n", argv[i]); + i++; + } + f = mafonction_f; + reponse_ft_any = ft_any(argv, *f); + printf("\nChaîne dont la taille est 1 ? ft_any : %d\n", reponse_ft_any); + return (0); +} diff --git a/with_mains_day10/ex04/a.out b/with_mains_day10/ex04/a.out new file mode 100644 index 0000000000000000000000000000000000000000..a4ac0b1cccb5a319481e7af340941dec5c2c18ed GIT binary patch literal 8520 zcmeHNO=ufO6duJ+W4TEsLn&>Y&?T)x5~!Vo97<~!Imyxqjaw(NptP8&WJ$J)v^LT% zjSmKc66mrRM4`}Ydk!=?hnD<-eXG;v;7dV=w#ZZkLv;|LME%}q)?TgK+za#I?dTO1S;6j%eth!h(*uk}`WRc;#~6!2Z}l^FgBiGE>=h`73NbbDp82tPNyqRW52_I%IEvL`NVv#xR@&=D4cIf<$F~nAWXdP$e#LUD|WeH z&8dKJzRy&?bIMORC_TC15W=xOFIZVou<{EM_pZlHm5e_x1ywdB$yL^1uWd~x)r z_yLuGa4?@=pK=F&2bV5>@VIRbC5FM| zqkjtR6l}yj`M&_BIkwS~{dp+0L80fI^jYiGFhaivmEZ-maIu5XQKwQKEfzAP*`;C@ zm}D4Ab$t0p=dZ8tjLm;{_P|#+CtE+i0b3l(4h>2@>0`1%j$^*muSNp|gvNObNnwKtOxLu{y-Ao;4epIS>TFco zk=TtWT%Osi-i^3s(=!|Lrm=OW)9Jv>s}GHt2Q`Qs4`Z#Ft-t`S*bgrbRG(l7dJXi< zmh9fz`bBnc%{<7*Ub{~5e!WS)y8kwuYv$i%?Jb_WW*vjRW42?fSK!4gwlRw)_xji2 z+w@Y+>ir0;o7`L8bW@LETyJEMj<1e8=-@ezxtCgZ@7-dJ^Mogx)q4?lvgw)+x4xw~ zZy6*w^~U#4Wv9zj1Lo~CksF<87N>u5&AaXfrk=#qJBjU71bovd6pbY#ZQvdOPAO;E6(hS~*~TaN+=E +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_count_if(char **tab, int (*f)(char*)) +{ + int count; + int i; + + count = 0; + i = 0; + while (tab[i]) + { + if (f(tab[i]) == 1) + count++; + i++; + } + return (count); +} diff --git a/with_mains_day10/ex04/main.c b/with_mains_day10/ex04/main.c new file mode 100644 index 0000000..77e8c4c --- /dev/null +++ b/with_mains_day10/ex04/main.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_count_if(char **tab, int(*f)(char*)); + +int ft_strlen(char *str) +{ + int len; + + len = 0; + while (str[len] != '\0') + len++; + return (len); +} + +int main(int argc, char **argv) +{ + int n; + int (*pf)(char*); + char *p; + + n = 0; + pf = &ft_strlen; + while (n < argc) + { + p = argv[n]; + printf("arg%d :\t%s\t\t\t%d\n", n + 1, p, ft_strlen(p)); + n++; + } + n = ft_count_if(argv, pf); + printf("\n%d - il y a %d arguments dont [f(argument)==1]\n", n, n); + return (0); +} diff --git a/with_mains_day10/ex05/a.out b/with_mains_day10/ex05/a.out new file mode 100644 index 0000000000000000000000000000000000000000..372c545da185907552950f7edd53e6d14422c316 GIT binary patch literal 8652 zcmeHNUr1zC7(cUWiD{#Op>5G!*@>+c|5GZhjN#qA)@tsqMg?-38E16ZaYknDkP;Kp zBzU_Sv+vP!y-CE}X#Z_q@ zYZ1;F48ZxM`1)jJh}OTc(#H%NxiO@}9x|FamxGIPIo6Jst;b~0+)9&ykX@};^=CC( zwwjzL`-gqmGdJ!J{OEE1mg&@;}s0N(*^+9Myk5!NPdA> zG*O%YyGhQtP zlK`Lkn?k>*HBZi?5uR9@_s1f9L5?5Euhz)VShkF8JD%0%JmUK|ycQcC+1CE%dtv5V zeorrsj=v&~jGFJ5VB-xo$(BYYV}xT=HGdoa4s=mXV2rq_MXA}Slk^LCk5RsbasnlB z)B^nyHpNe#Vr&uRBT#C$3cZJ>TK(2~Kl)QncEM{xDKUBvJClicXC&Scf8brJi>kiL7suqcyu%wo3~9p!QuWZ7X69i0Q0L5%aqr zmrAAX>s#Cf20dtSv)BH< z_gBnij<$HacTuA)pa)8OL{ifpz|t_)Gb0G^boaIky)U#2eLX25n2?2JRFHlCNYIxQ zJc&An@2ic^STqK&R@3_Q^|T9mzhnCtxP;o>Yd(*S)c5O8B0myqN&8g#-t9w4O5ds^ zRHx-skNs;S)R4o9>9CeX^re6k#`l}G&8a&KI1D%pI1D%pI1D%pI1D%pI1D%pI1D%p zI1K#17-(v1xl9>1c{yE$`vO;aVD2iPP5R<9>{6U%ymZN?U6OM@?s;*kouT-6i>*h< z7mlDQF2KKl3uZZ_2f8@!@2mLy91kuA14%iEyKx`EoDQ)w^S*GDy-ep8?1aq237&|> zW#)}V19CVPt20!2LZ2$lO literal 0 HcmV?d00001 diff --git a/with_mains_day10/ex05/ft_is_sort.c b/with_mains_day10/ex05/ft_is_sort.c new file mode 100644 index 0000000..ba5b940 --- /dev/null +++ b/with_mains_day10/ex05/ft_is_sort.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_sort(int *tab, int length, int (*f)(int, int)) +{ + int i; + int k; + + i = 0; + k = 0; + while (i < length - 1 && k <= 0) + { + k = f(tab[i], tab[i + 1]); + i++; + } + k = (k <= 0) ? 1 : 0; + return (k); +} diff --git a/with_mains_day10/ex05/main.c b/with_mains_day10/ex05/main.c new file mode 100644 index 0000000..c29a7bf --- /dev/null +++ b/with_mains_day10/ex05/main.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_is_sort(int *tab, int length, int(*f)(int, int)); + +int fonction_f(int i, int j) +{ + return (i - j); +} + +int main(void) +{ + int tab1[3] = {13, 37, 42}; + int tab2[3] = {42, 13, 37}; + int tab3[3] = {1337, 1337, 1337}; + int k; + + k = ft_is_sort(tab1, 3, &fonction_f); + printf("%d {13, 37, 42} est un tableau %s\n", k, + (k == 1) ? "trié" : "non trié"); + k = ft_is_sort(tab2, 3, &fonction_f); + printf("%d {42, 13, 37} est un tableau %s\n", k, + (k == 1) ? "trié" : "non trié"); + k = ft_is_sort(tab3, 3, &fonction_f); + printf("%d {1337, 1337, 1337} est un tableau %s\n", k, + (k == 1) ? "trié" : "non trié"); + return (0); +} diff --git a/with_mains_day10/ex06/Makefile b/with_mains_day10/ex06/Makefile new file mode 100644 index 0000000..97e4b04 --- /dev/null +++ b/with_mains_day10/ex06/Makefile @@ -0,0 +1,13 @@ +DEST = do-op +SRC = srcs/main.c srcs/fonctions.c srcs/operations.c +HEADER = includes/ + +all: compile + +compile: + gcc -Wall -Wextra -Werror -I$(HEADER) $(SRC) -o $(DEST) + +clean: + rm -f $(DEST) + +re: fclean all \ No newline at end of file diff --git a/with_mains_day10/ex06/do-op b/with_mains_day10/ex06/do-op new file mode 100644 index 0000000000000000000000000000000000000000..2a780e18746424977892ec4f6c06ff78ec5c8666 GIT binary patch literal 9188 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/14 12:15:08 by rfseffa #+# #+# */ +/* Updated: 2018/09/14 16:22:02 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +void ft_putchar(char c); +void ft_putstr(char *str); +void ft_putnbr(int i); +int ft_atoi(char *str); +int ft_str_is_alpha(char *str); +int ft_is_numeric(char *str); +int sub(int i, int j); +int add(int i, int j); +int div(int i, int j); +int mod(int i, int j); +int multiply(int i, int j); + +#endif diff --git a/with_mains_day10/ex06/srcs/fonctions.c b/with_mains_day10/ex06/srcs/fonctions.c new file mode 100644 index 0000000..0fb2f67 --- /dev/null +++ b/with_mains_day10/ex06/srcs/fonctions.c @@ -0,0 +1,92 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fonctions.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/14 12:30:08 by rfseffa #+# #+# */ +/* Updated: 2018/09/14 16:22:02 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putstr(char *str) +{ + int i; + + i = 0; + while (str[i] != '\0') + { + ft_putchar(str[i]); + i++; + } +} + +void ft_putnbr(int nb) +{ + if (nb < 0) + { + ft_putchar('-'); + nb = -nb; + } + if (nb >= 10) + { + ft_putnbr(nb / 10); + ft_putnbr(nb % 10); + } + else + { + ft_putchar(nb + '0'); + } +} + +int ft_str_is_alpha(char *str) +{ + int i; + + i = 0; + while (str[i] != '\0') + { + if ((str[i] >= 'a' && str[i] <= 'b') || + (str[i] >= 'A' && str[i] <= 'Z')) + i++; + else + return (0); + } + return (1); +} + +int ft_atoi(char *str) +{ + int i; + int negativ; + int number; + + i = 0; + negativ = 0; + number = 0; + while ((str[i] == ' ') || (str[i] == '\t') || (str[i] == '\n') + || (str[i] == '\v') || (str[i] == '\f') || (str[i] == '\r')) + i++; + if (str[i] == 45) + negativ = 1; + if ((str[i] == 45) || (str[i] == 43)) + i++; + while (str[i] >= 48 && str[i] <= 57) + { + number *= 10; + number += ((int)str[i] - 48); + i++; + } + if (negativ == 1) + return (-number); + else + return (number); +} diff --git a/with_mains_day10/ex06/srcs/main.c b/with_mains_day10/ex06/srcs/main.c new file mode 100644 index 0000000..c309b27 --- /dev/null +++ b/with_mains_day10/ex06/srcs/main.c @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/14 12:15:08 by rfseffa #+# #+# */ +/* Updated: 2018/09/14 16:22:02 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +int is_valid_operator(char *str) +{ + if (str[0] != '\0' && + (str[0] == '+' || str[0] == '-' || str[0] == '/' || + str[0] == '*' || str[0] == '%')) + return (1); + else + return (0); +} + +int calculate(int first, char ope, int second) +{ + int (*ops[5])(int x, int y) = {&add, &sub, &multiply, &div, &mod}; + + if (ope == '+') + return (ops[0](first, second)); + else if (ope == '-') + return (ops[1](first, second)); + else if (ope == '*') + return (ops[2](first, second)); + else if (ope == '/') + return (ops[3](first, second)); + else if (ope == '%') + return (ops[4](first, second)); + else + return (0); +} + +int operation_is_valid(char ope, int second) +{ + if (ope == '/' && second == 0) + { + ft_putstr("Stop : division by zero\n"); + return (0); + } + else if (ope == '%' && second == 0) + { + ft_putstr("Stop : modulo by zero\n"); + return (0); + } + else + return (1); +} + +int main(int argc, char **argv) +{ + int first; + int second; + + if (argc != 4) + return (0); + if (!is_valid_operator(argv[2])) + { + ft_putstr("0\n"); + return (0); + } + if (ft_str_is_alpha(argv[1]) || ft_str_is_alpha(argv[3])) + { + ft_putstr("0\n"); + return (0); + } + first = ft_atoi(argv[1]); + second = ft_atoi(argv[3]); + if (!operation_is_valid(argv[2][0], second)) + return (0); + ft_putnbr(calculate(first, argv[2][0], second)); + ft_putchar('\n'); + return (0); +} diff --git a/with_mains_day10/ex06/srcs/operations.c b/with_mains_day10/ex06/srcs/operations.c new file mode 100644 index 0000000..fcee4ca --- /dev/null +++ b/with_mains_day10/ex06/srcs/operations.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* operations.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/14 12:30:08 by rfseffa #+# #+# */ +/* Updated: 2018/09/14 16:22:02 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +int sub(int i, int j) +{ + return (i - j); +} + +int div(int i, int j) +{ + return (i / j); +} + +int mod(int i, int j) +{ + return (i % j); +} + +int add(int i, int j) +{ + return (i + j); +} + +int multiply(int i, int j) +{ + return (i * j); +} diff --git a/with_mains_day10/ex07/a.out b/with_mains_day10/ex07/a.out new file mode 100644 index 0000000000000000000000000000000000000000..0b9e51b856f97dd90db9489f16da835ee57b0b25 GIT binary patch literal 8568 zcmeHMQD_`h6n)b~T{Lkvpf#~69fPsfLej?2C`Q;wM<=wat<6Fa!gF`CF$=q!uschV zk3eJ+%{oRFr6A(B_~A#s{V1D8vW0?f|NIg(QFdVqp#%vfbUk#rOlo0l@fc%F2Cua;w#*brjCFxEFy~iB-cdhL-+zy+jU+Xy z|Ef`*U*X94n0kGz(Z!1QH`jb--co^^fwg)A|2(_sg*6( z70Q>h!ipYSK$osZ6)TdzL{mq*{dq+T3#&al!{Cv>7Yu^7tZURMvEvvcI2*mL{Pcaknh zQJ8h~&!PViHo~69zg8HdT%9l2_NO3U0lUe0PLA3yAL5;};*Nb9iUP*t!uqqBbblfq z>7STSOh6|(0j70)btnAeZ&SnV-`s3F74I3l_abb7j^cC=i!TvWHIi1US&b7-P8tC1xsP3c1QufC;PL?4D*`Am|`My`Y&37#V^F3xPT`zA;JE*AQ=1{lI*$sP0foV_}EMHwuHb z0|>u_wW#jWAbccrC~MCQ?i%Y-F1V{j?`pu>}u=3w`kIB%_v~~LECx#518(1xuTZ)xqKX$i`7*=hFrN$n_&FpAK%C~ zl7)v+RRmU=h_W`!WSi`~BLyV;RG0zZCVSPkLadwpn+(9=+?WBs%iLM_?j&BSE+)I0A2Q3m*G5u z`(a#OUrn<-OZz(ld(sWwqv(xDbJse?IT3Egdza|PN&@6VNDV?MMP`+#JSfC_XcY?Cy zw`}y^<2YC*0r!a1off)t-#;MqLc2ZwhS2HWk^D!%=t;C_6s=pQUxnfhKR~jA8|cF| aa;ni?iDj_Mv_vYETM#&)9fH-Gp8W&73I3!2 literal 0 HcmV?d00001 diff --git a/with_mains_day10/ex07/ft_sort_wordtab.c b/with_mains_day10/ex07/ft_sort_wordtab.c new file mode 100644 index 0000000..8e30804 --- /dev/null +++ b/with_mains_day10/ex07/ft_sort_wordtab.c @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_wordtab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/14 16:10:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/14 17:22:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + int i; + + i = 0; + while (s1[i] != '\0' && s2[i] != '\0') + { + if (s1[i] != s2[i]) + return (s1[i] - s2[i]); + i++; + } + if ((s1[i] == '\0' && s2[i] != '\0') || (s2[i] == '\0' && s1[i] != '\0')) + return (s1[i] - s2[i]); + return (0); +} + +void ft_swap(char **a, char **b) +{ + char *tmp; + + tmp = *a; + *a = *b; + *b = tmp; +} + +void ft_sort_wordtab(char **tab) +{ + int i; + int sorted; + + sorted = 0; + while (!sorted) + { + i = 0; + sorted = 1; + while (tab[++i]) + if (ft_strcmp(tab[i - 1], tab[i]) > 0) + { + ft_swap(tab + i - 1, tab + i); + sorted = 0; + } + } + } +} + diff --git a/with_mains_day10/ex07/main.c b/with_mains_day10/ex07/main.c new file mode 100644 index 0000000..4e914e6 --- /dev/null +++ b/with_mains_day10/ex07/main.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rfseffa +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/09/14 16:10:04 by rfseffa #+# #+# */ +/* Updated: 2018/09/14 17:22:16 by rfseffa ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_sort_wordtab(char **tab); + +int main(void) +{ + char **tab; + int k; + + tab[0][0] = '1'; + tab[0][1] = '\0'; + tab[1][0] = '3'; + tab[1][1] = '\0'; + tab[2][0] = '7'; + tab[2][1] = '\0'; + tab[3][0] = '3'; + tab[3][1] = '\0'; + k = 0; + while (k < 4) + { + printf("%s ", tab[k]); + k++; + } + /* + ft_sort_wordtab(tab); + k = 0; + while (k < 4) + { + printf("%s ", tab[k]); + k++; + } + return (0); + */ +} diff --git a/with_mains_day10/ex08/main.c b/with_mains_day10/ex08/main.c new file mode 100644 index 0000000..ee18d48 --- /dev/null +++ b/with_mains_day10/ex08/main.c @@ -0,0 +1,28 @@ +#include +#include + +int mafonction_g(int i) +{ + return (10 * i); +} + +int main(void) +{ + int tab[4] = {1,2,3,4}; + int *dTab; + int k; + + int (*g)(int); /*déclaration du pointeur sur fonction pour g*/ + + g = mafonction_g; /*Initialisation pour g*/ + + dTab = ft_map(tab, 4, (*g)); /*Appel g*/ + + k = 0; + while (k < 4) + { + printf("-g multiplie par 10 le contenu de la cellule %d\n", dTab[k]); + k++; + } + return(0); +} \ No newline at end of file diff --git a/with_mains_day10/ex09/main.c b/with_mains_day10/ex09/main.c new file mode 100644 index 0000000..ee18d48 --- /dev/null +++ b/with_mains_day10/ex09/main.c @@ -0,0 +1,28 @@ +#include +#include + +int mafonction_g(int i) +{ + return (10 * i); +} + +int main(void) +{ + int tab[4] = {1,2,3,4}; + int *dTab; + int k; + + int (*g)(int); /*déclaration du pointeur sur fonction pour g*/ + + g = mafonction_g; /*Initialisation pour g*/ + + dTab = ft_map(tab, 4, (*g)); /*Appel g*/ + + k = 0; + while (k < 4) + { + printf("-g multiplie par 10 le contenu de la cellule %d\n", dTab[k]); + k++; + } + return(0); +} \ No newline at end of file