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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms