ft_malloc/libft/ft_strchr.c
2025-11-28 19:50:58 +01:00

29 lines
1.2 KiB
C
Executable file

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 16:59:05 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:40 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns the index of the first character c of the string
// /!\SEGFAULT if str is NULL
//returns ft_strlen(s) if c is \0
char *ft_strchr(const char *s, int c)
{
if ((char)c == '\0')
return ((char *)(s + ft_strlen(s)));
while (*s)
{
if (*s == (char)c)
return ((char *) s);
s++;
}
return (NULL);
}