Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
963 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* libft.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_putchar.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */ | ||
/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <unistd.h> | ||
|
||
void ft_putchar(char c) | ||
{ | ||
write(1, &c, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_putstr.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strcmp.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strlen.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_swap.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_foreach.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@1337.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/09/12 04:23:04 by rfseffa #+# #+# */ | ||
/* Updated: 2018/09/12 08:59:16 by rfseffa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
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); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_map.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ | ||
/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdlib.h> | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */ | ||
/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
//#include <stdlib.h> | ||
|
||
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); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_any.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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); | ||
} |
Oops, something went wrong.