ft_strchr

Subject

STRCHR(3) (simplified)

NAME
    strchr -- locate character in string
SYNOPSIS
    char *strchr(const char *s, int c);
DESCRIPTION
    The strchr() function locates the first occurence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be part of the string; therefor if c is '\0', the function locate the terminating '\0'.
RETURN VALUES
    The function strchr() return a pointer to the located character, or NULL if the character does not appear in the string.

Understandable explanation

The strchr() function searches for one character in a string. If it finds the character, it returns a pointer to the first occurence of this specific character.

If it don't find any occurence of this character, it returns NULL.

We also have to return a pointer to the character if the character is \0.

Hints

ft_strchr.c
char *ft_strchr(const char *s, int c)
{
    /* loop over the whole string */
    /* check if current character is equal to the one we have to find */
    /* once we looped over the whole string, check again for the character
     * in case the character we have to find is '\0'
     */
    /* if we didn't find c in the string, return NULL */
}

Commented solution

ft_strchr

Last updated

Was this helpful?