On this page
strstr
Prev: strchr | Up: string.h | Next: strerror
Rel: string.h, stdlib.h & string.h Guide
Ref: cppreference — strstr
Tags: #public #prog #c #stdlib #string #tier/standard
Include
#include <string.h>
Signature & Overview
char *strstr(const char *haystack, const char *needle);
Finds the first occurrence of substring needle inside haystack (or NULL).
Notes & Pitfalls
- Returns pointer to first match or
NULL: Searching for""returnshaystack.
Example
#include <assert.h>
#include <string.h>
int main(void) {
const char *p = strstr("hello world", "world");
assert(p != NULL && strcmp(p, "world") == 0);
}
Linked from
Related notes
- tuts/c/stdlib/string/strchr Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strerror Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/stdlib_and_string_h Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/string/memchr shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memcmp shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memcpy shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memmove shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memset shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strcat shared tags: #c, #prog, #stdlib, #string, #tier