strchr(3)

๐Ÿ’– strchr(3) โ€” string search character ๐Ÿ’–

okay bestie, welcome to the strchr page from the Library Functions Manual โœจ it's giving "find the first matching letter and go feral" energy and honestly? we're obsessed. let's get into it ๐ŸŽ€


๐ŸŒธ NAME ๐ŸŒธ

strchr โ€” string search character ๐Ÿ”

no cap, that's literally it. we're hunting a character inside a string.


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library โ€” link with -lc ๐Ÿซถ


โœจ SYNOPSIS โœจ

#include <string.h>

char *strchr(const char *s, int c);

like always, pull in <string.h> first or the compiler will simply not know her ๐Ÿ’…


๐Ÿ’ซ DESCRIPTION ๐Ÿ’ซ

so strchr() hands you back a pointer to the first occurrence of the character c inside the string s. first one only. she does not care about the rest ๐Ÿ‘‘

and get this, she's equivalent to both of these expressions (yes, both, iconic behavior):

memchr(s, c, strlen(s) + 1)
strpbrk(s, (char [2]){c, '\0'})

main character energy fr fr ๐ŸŒˆ


๐ŸŽ€ RETURN VALUE ๐ŸŽ€

strchr() returns a pointer to the matched character โ€” or NULL if that character is nowhere to be found ๐Ÿ˜ญ like, not in the string at all.

BUT here's the tea ๐Ÿ“: the terminating null byte is considered part of the string. so if you pass c as '\0', strchr() happily returns a pointer to the terminator itself. she is in there. she counts. periodt ๐Ÿ’€


๐Ÿฆ‹ ATTRIBUTES ๐Ÿฆ‹

for the whole explanation of what these terms even mean, go peek at attributes(7) โ€” she explains it better than I can ngl ๐Ÿ’œ

  • Interface โ€” strchr()
  • Attribute โ€” Thread safety
  • Value โ€” MT-Safe ๐Ÿ”ฅ

translation: safe to call from multiple threads at once, no drama, no chaos, no vibe check failures โœจ


โญ STANDARDS โญ

  • C11
  • POSIX.1-2008

certified, standards-approved, no notes ๐Ÿ‘‘


๐ŸŒˆ HISTORY ๐ŸŒˆ

she's been around. like, around around:

  • POSIX.1-2001
  • C89
  • SVr4
  • 4.3BSD

a true legacy icon, we stan a consistently reliable function ๐Ÿ’…


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

the whole girl group, if you wanna meet the rest of the fam:


that's the whole page bestie, go forth and find your characters ๐Ÿงš๐Ÿ’–

this has been Linux man-pages 6.20, dated 2026-08-10, signing off โ€” stay slaying, stay MT-Safe, and always null-terminate ur strings ๐Ÿซถโœจ

๐Ÿ“ฆ 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