From 39b3f2bc4ea6aa99ef7df5eb3239055bfe13ecd5 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Wed, 23 Mar 2022 14:26:11 +0100 Subject: [PATCH] add arrintchr --- Makefile | 4 +++- includes/libft.h | 4 +++- srcs/ft_arrintchr.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 srcs/ft_arrintchr.c diff --git a/Makefile b/Makefile index 282d82c..ce72c00 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,9 @@ SRCS = ft_memset.c \ ft_smaller.c \ ft_sign.c \ ft_sqrt.c \ - ft_free_tab.c + ft_free_tab.c \ + \ + ft_arrintchr.c ODIR = ./builds diff --git a/includes/libft.h b/includes/libft.h index 058d3e3..da6babe 100644 --- a/includes/libft.h +++ b/includes/libft.h @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/25 14:45:53 by hulamy #+# #+# */ -/* Updated: 2020/02/27 18:06:10 by hulamy ### ########.fr */ +/* Updated: 2022/03/23 14:22:33 by simplonco ### ########.fr */ /* */ /* ************************************************************************** */ @@ -113,4 +113,6 @@ int ft_sign(int i); int ft_sqrt(int i); void ft_free_tab(char **tab); +int ft_arrintchr(int * intarr, int comp, size_t size); + #endif diff --git a/srcs/ft_arrintchr.c b/srcs/ft_arrintchr.c new file mode 100644 index 0000000..936ffc9 --- /dev/null +++ b/srcs/ft_arrintchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_arrintchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: simplonco +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/23 14:25:28 by simplonco #+# #+# */ +/* Updated: 2022/03/23 14:25:37 by simplonco ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* + * search through an arr of int if it contains the int comp + * return 0 if found, 1 otherwise + */ + +#include "libft.h" + +int ft_arrintchr(int * intarr, int comp, size_t size) +{ + size_t i; + + if (!intarr) + return 1; + i = -1; + while (++i < size) + if (intarr[i] == comp) + return 0; + return 1; +}