strstr(3) Library Functions Manual strstr(3)

strstr - string search substring

Standard C library (libc-lc)

#include <string.h>
char *strstr(const char *haystack, const char *needle);

strstr() finds the first occurrence of the substring needle in the string haystack.

The terminating null bytes ('\0') are not compared.

It is equivalent to


memmem(haystack, strlen(haystack), needle, strlen(needle))

strstr(3) returns a pointer to the beginning of the located substring, or NULL if the substring is not found.

If needle is the empty string, the return value is always haystack itself.

For an explanation of the terms used in this section, see attributes(7).

Interface Attribute Value
strstr () Thread safety MT-Safe

C11, POSIX.1-2008.

POSIX.1-2001, C89.

strcasestr(3), strchr(3), string(3), strpbrk(3), strsep(3), strspn(3), wcsstr(3)

2026-08-10 Linux man-pages 6.19