Jump to: navigation, search

Description

The strrchr() function locates the last 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 strrchr() function returns a pointer to the located character, or a null pointer if c does not occur in the string.

Prototype

Declared in string.h

The C89/C99 prototype is:

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

Implementation

In standard C, this can be implemented as:

char *strrchr(const char *s, int c)
{
    char* ret=0;
    do {
        if( *s == (char)c )
            ret=s;
    } while(*s++);
    return ret;
}

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

References

The C Standard, 7.21.5.5 (C99 numbering)

Personal tools