STRRCHR(3P)
π STRRCHR(3P) β the string-scanning girlie π
okay bestie, so this one's from the POSIX Programmer's Manual. Quick heads-up before we get into it: this whole page is part of that manual, and the Linux implementation of this interface may differ β so if you're on Linux, go peek at the corresponding Linux manual page for the deets. Or, plot twist, the interface might not even be implemented on Linux at all. π Not us finding out the hard way.
β¨ NAME β¨
strrchr β string scanning operation
no cap, that's the whole vibe. it scans. it finds. it serves. π
πΈ SYNOPSIS πΈ
#include <string.h>
char *strrchr(const char *s, int c);
π¦ DESCRIPTION π¦
okay so first things first, the tea: everything described on this reference page is aligned with the ISO C standard. If anything here conflicts with the requirements in the ISO C standard, that conflict is unintentional β nobody's trying to start drama. This volume of POSIX.1β2017 defers to the ISO C standard. periodt.
Now the actual function, because this is the good part:
The strrchr() function shall locate the last occurrence of c (converted to a char) in the string pointed to by s. π
and bestie, listen β the terminating NUL character is considered to be part of the string. So yes, that NUL is invited to the party. it's a main character too. π
π₯ RETURN VALUE π₯
Upon successful completion, strrchr() shall return a pointer to the byte β or a null pointer if c does not occur in the string. that's it. that's the whole return. if she's not there, you get NULL and you just have to cope. π
π ERRORS π
No errors are defined. not a single one. she's unproblematic fr fr.
Also, quick note: the following sections are informative (iykyk β that means they're the lore, not the law).
π EXAMPLES π
Finding the Base Name of a File
okay this example is genuinely iconic. The following example uses strrchr() to get a pointer to the base name of a file.
Here's the move: strrchr() searches backwards through the name of the file to find the last '/' character in name. That pointer plus one will point to the base name of the file. π«Ά
#include <string.h>
...
const char *name;
char *basename;
...
basename = strrchr(name, '/') + 1;
...
the + 1 is doing SO much heavy lifting and honestly? we love her for it. β
π APPLICATION USAGE π
None. nothing to add, she said what she said. π
π§ RATIONALE π§
None. no thoughts, head empty, only function. β¨
π FUTURE DIRECTIONS π
None. the future is... also none. she's stable. she's thriving. she's not going anywhere. π
πΈ SEE ALSO πΈ
strchr()- The Base Definitions volume of POSIX.1β2017,
<string.h>
π COPYRIGHT π
okay so the legal bit, and we're keeping it exactly as it is because lawyers are scary and also correct:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
also: any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . π«Ά
and that's the page bestie!! π this one's IEEE/The Open Group, 2017, and it's the STRRCHR(3P) page β go forth and find your last occurrence, you absolute legend. ππ¦β¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms