strstr(3)

โœจ strstr(3) โœจ

okay bestie, so this is strstr(3) from the Library Functions Manual, and it's literally the "find my substring" function. she's simple, she's iconic, she's been holding down C string searching since forever ๐Ÿ’– let's get into it


๐ŸŽ€ NAME ๐ŸŽ€

strstr โ€” string search substring

like. the name says it all. string, search, substring. no cap.


๐Ÿ›๏ธ LIBRARY ๐Ÿ›๏ธ

Standard C library (libc, -lc)

the one and only. she's built in, she's always there for you ๐Ÿซถ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <string.h>

char *strstr(const char *haystack, const char *needle);

yes you have to #include <string.h> first, don't be that girl who forgets the include ๐Ÿ™ˆ


๐Ÿ’… DESCRIPTION ๐Ÿ’…

so strstr() finds the first occurrence of the substring needle in the string haystack. it's giving "you dropped this needle in a haystack and I found it immediately, you're welcome" ๐Ÿ”ฅ

the terminating null bytes ('\0') are not compared. nope. not part of the vibe. those two little terminators get to sit this one out ๐Ÿ’€

it is equivalent to

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

so if you already knew memmem, you basically already knew this. academic besties fr fr โœจ


๐Ÿฆ‹ RETURN VALUE ๐Ÿฆ‹

strstr(3) returns a pointer to the beginning of the located substring, or NULL if the substring is not found. no substring, no pointer, no crumbs. NULL is the ghosting ๐Ÿ’€

but wait โ€” plot twist โ€” if needle is the empty string, the return value is always haystack itself. she's already there. she never left. periodt. ๐Ÿ‘‘


๐ŸŒˆ ATTRIBUTES ๐ŸŒˆ

for an explanation of the terms used in this section, see attributes(7). here's the vibe check:

  • strstr() โ€” Thread safety: MT-Safe ๐ŸŽ€

MT-Safe means she plays nice with all your threads, no drama, no fighting, we love a peaceful queen ๐Ÿ’–


โญ STANDARDS โญ

C11, POSIX.1-2008.

certified. standardized. official. the committee said slay and she ate ๐Ÿ”ฅ


๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

POSIX.1-2001, C89.

she's been here since C89, bestie. ancient. timeless. a true main character who predates most of your faves ๐ŸŒธ


๐Ÿงš SEE ALSO ๐Ÿงš

go read those too, they're all part of the same friend group ๐Ÿซถ


okay that's the whole page!! ๐Ÿ’œ this was brought to you by Linux man-pages 6.20, dated 2026-08-10, and written by the strstr(3) girlies. now go find your substring, you've got this โœจ๐ŸŽ€๐Ÿ’–

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms