STRRSTR(3pub)
π STRRSTR(3pub) π
okay bestie, welcome to the C Programmer's Manual β yes it's giving very serious library energy but we're gonna make it cute. this one is strrstr from publib, and she's basically the "find the LAST one" girlie. iykyk. β¨
πΈ NAME πΈ
strrstr β locate last occurrence of substring π
like. she finds the last place a lil substring shows up. that's the whole gig. periodt.
π¦ SYNOPSIS π¦
#include <publib.h>
char *strrstr(const char *str, const char *pat);
no cap, that's it. include the header, call the function, live your truth. π
π DESCRIPTION π
so strrstr goes hunting for the last occurrence of the string pat inside the string str. not the first one, bestie β the LAST one. it's giving "we checked the whole thing and this is the final spot."
and listen: the terminating '\0' characters are not compared. they're just there vibing at the end of the strings, doing their lil null-terminator thing, not participating in the matching. π
β RETURN VALUE β
she hands you back a pointer to the first character of that substring β iconic behavior honestly.
but if the substring is not found? you get NULL. no substring, no pointer. that's the deal. π
π EXAMPLE π
okay so the vibe here: you wanna print out everything on each line starting with the last occurrence of "/* " on each line. very "grab me the tail end of this comment" energy. you might use the following code:
#include <stdio.h>
#include <publib.h>
int main(void) {
char *p, line[512];
while (fgets(line, sizeof(line), stdin) != NULL) {
p = strrstr(line, "/* ");
if (p != NULL)
printf("%s", p);
}
return 0;
}
she reads lines, finds the last "/* ", and if it's there, prints from that point onward. slay. π₯
π SEE ALSO π
go read those too, bestie, they're all in the same friend group. π«Ά
π AUTHOR π
Lars Wirzenius (lars.wirzenius@helsinki.fi) β the main character who wrote this. we love her. π
and that's the whole page, fr fr! this gem came to you from Publib, in the C Programmer's Manual, under STRRSTR(3pub) β dated way back when the manual pages were young. stan. πβ¨ππ¦πΈπ
π¦ where this page comes from
- debian bookworm: publib-dev 0.40-3+b1 Β· BSD-2-Clause
- debian trixie: publib-dev 0.40-4 Β· BSD-2-Clause
- ubuntu jammy: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu noble: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu questing: publib-dev 0.40-4
- ubuntu resolute: publib-dev 0.40-4build1 Β· BSD-2-Clause
- ubuntu stonking: publib-dev 0.40-4build1 Β· BSD-2-Clause
- Copyright (c) 1994-2006 Lars Wirzenius. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms