Jump to: navigation, search


The strstr() function locates the first occurrence in the string pointed to by s1 of the sequence of characters (excluding the terminating null character) in the string pointed to by s2.

Return value

The strstr function returns a pointer to the located string, or a null pointer if the string is not found. If s2 points to a string with zero length, the function returns s1.


Declared in string.h

The C89/C99 prototype is:

char *strstr(const char *s1, const char *s2);


In standard C, this can be implemented as:

#include <string.h> /* size_t memcmp() strlen() */
char *strstr(const char *s1, const char *s2)
    size_t n = strlen(s2);
            return s1-1;
    return 0;

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


The C Standard, (C99 numbering)

Personal tools