From d732047d6681b1f64f7907d1c0413abdaab76050 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 6 Jul 2019 08:42:30 +0200 Subject: c03 and begin c04 --- c03/ex04/ft_strstr.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 c03/ex04/ft_strstr.c (limited to 'c03/ex04') diff --git a/c03/ex04/ft_strstr.c b/c03/ex04/ft_strstr.c new file mode 100644 index 0000000..e27ffc8 --- /dev/null +++ b/c03/ex04/ft_strstr.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/05 15:20:54 by cacharle #+# #+# */ +/* Updated: 2019/07/05 16:46:57 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#define MY_NULL 0x0 + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (*str != '\0') + { + counter++; + str++; + } + return (counter); +} + +char *ft_strstr(char *str, char *to_find) +{ + int i; + + if (!ft_strlen(to_find)) + return str; + while (*str) + { + i = 0; + while (to_find[i] && str[i]) + { + if (to_find[i] != str[i]) + break; + i++; + } + if (i == ft_strlen(to_find)) + return (str); + str++; + } + return (MY_NULL); +} -- cgit