SDL_strrchr(3)

πŸ’– SDL_strrchr β€” the SDL3 glow-up πŸ’–

okay bestie, welcome to SDL_strrchr(3), one of the SDL3 FUNCTIONS ✨ it's giving "find the last one" energy and honestly? iconic.


🌸 NAME 🌸

SDL_strrchr β€” Search a string for the last instance of a specific byte. that's it, that's the whole vibe πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_stdinc.h>

char * SDL_strrchr(const char *str, int c);

like... she's short, she's simple, she works. periodt. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

so the tea is: the search must keep going until it hits a null terminator byte, because that's what ends the string. no skipping ahead, no shortcuts, she's committed to the bit 🫢

and now the part everyone gets wrong β€” note that this looks for _bytes_, not _characters_. so you literally cannot match against a Unicode codepoint > 255, regardless of character encoding. not "shouldn't", not "it's discouraged" β€” cannot. the byte is the byte, bestie 😭


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • str β€” the string to search. Must not be NULL. like, do not. πŸ™ˆ
  • c β€” the byte value to search for.

⭐ RETURN VALUE ⭐

Returns a pointer to the last instance of c in the string, or NULL if it's not found. so either you get your lil pointer back or you get NULL and you deal with it πŸ’€


πŸ’œ THREAD SAFETY πŸ’œ

It is safe to call this function from any thread. yes queen, no locking drama, no "only from the main thread" nonsense, just go off πŸ”₯


🌈 AVAILABILITY 🌈

This function is available since SDL 3.2.0. so if you're on something older... it's not there, sorry babe πŸ˜”


fr fr, the one thing to remember: it's the last byte, and it's a byte not a character. iykyk πŸ‘‘

stay hydrated, read your return values, and go find that last byte bestie πŸ’–βœ¨πŸŒΈπŸ¦‹

β€” written with love from the Simple Directmedia Layer girlies, straight out of SDL 3.4.18, and yeah, this is SDL_strrchr(3) signing off πŸŽ€πŸ’…

πŸ“¦ where this page comes from