Browse Source

ft_strr?chr

master
Elouan MARTINET 4 years ago
parent
commit
8729e92383
  1. 2
      Makefile
  2. 30
      ft_strchr.c
  3. 31
      ft_strrchr.c

2
Makefile

@ -20,6 +20,7 @@ SRC := \
ft_putnbr.c \
ft_putstr.c \
ft_strcat.c \
ft_strchr.c \
ft_strcmp.c \
ft_strcpy.c \
ft_strdup.c \
@ -28,6 +29,7 @@ SRC := \
ft_strncmp.c \
ft_strncpy.c \
ft_strnstr.c \
ft_strrchr.c \
ft_strstr.c \
ft_tolower.c \
ft_toupper.c

30
ft_strchr.c

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 19:52:56 by emartine #+# #+# */
/* Updated: 2017/11/07 19:52:58 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
size_t i;
i = 0;
if (c == 0)
{
while (s[i])
i++;
return ((char *)s + i);
}
while (s[i])
if (s[i] == c)
return ((char *)s + i);
return (NULL);
}

31
ft_strrchr.c

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 19:58:19 by emartine #+# #+# */
/* Updated: 2017/11/07 19:58:20 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
size_t i;
i = 0;
while (s[i])
i++;
if (c == 0)
return ((char *)s + i);
while (i > 0)
{
i--;
if (s[i] == c)
return ((char *)s + i);
}
return (NULL);
}
Loading…
Cancel
Save