Jump to: navigation, search


The strchr() function locates the first occurrence 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.

Return value

The strchr() function returns a pointer to the located character, or a null pointer if the character does not occur in the string.


Declared in string.h

The C89/C99 prototype is:

char *strchr(const char *s, int c);


In standard C, this can be implemented as:

char *strchr(const char *s, int c)
    while (*s != (char)c)
        if (!*s++)
            return 0;
    return (char *)s;

Compilable unit, portable C90 in implementation namespace; public domain; past reviewers: none; current reviews: none


The C Standard, (C99 numbering)

Personal tools