On this page
  1. strstr
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

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

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