SDL_strtok_r(3)
π SDL_strtok_r(3) π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where today's main character is SDL_strtok_r. she slices strings. she's literally the strtok_r() you already know and love, except she does exactly the same thing without needing access to a C runtime. no C runtime? no problem. she's that girl. π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
char * SDL_strtok_r(char *str, const char *delim, char **saveptr);
like. look at her. iconic signature, no notes. π
πΈ DESCRIPTION πΈ
so the whole vibe here is: break a string up into a series of tokens. that's the job. that's the assignment. she ate.
to start tokenizing a brand-new string, str should be the non-NULL address of the string you wanna start tokenizing. then, for all your future calls where you want the next token from that same string, you pass a NULL instead. that's it. that's the pattern. iykyk. π¦
β οΈ okay this part is important and i need you to actually read it: this function will overwrite pieces ofstrwith null chars to split it into tokens. so she cannot be used withconst/read-only strings! not a suggestion, not a preference, she will genuinely wreck them. π
and saveptr? she just needs to point to a char * that can be overwritten. SDL uses that lil guy to save tokenizing state between calls. it gets initialized if str is non-NULL, and it gets used to resume tokenizing when str is NULL. she's remembering where you left off so you don't have to. bestie behavior fr fr. π«Ά
π FUNCTION PARAMETERS π
strβ the string to tokenize, orNULLto continue tokenizing. (yes,NULLmeans "keep going", that's the whole trick π«)delimβ the delimiter string that separates tokens.saveptrβ pointer to achar *, used for ongoing state. she lives here between calls. give her a home. π
β RETURN VALUE β
returns a pointer to the next token, or NULL if no tokens remain. that NULL at the end? that's her little goodbye. π₯Ί
π THREAD SAFETY π
it is safe to call this function from any thread. periodt. every thread can have her. she's for the girls and the threads. π
π¦ AVAILABILITY π¦
this function is available since SDL 3.2.0. so if you're on something older, no she's not there yet, sorry bestie. π
one more time for the people in the back: non-NULLstrto start,NULLto continue,saveptrcarries the state, and NEVER hand her aconststring because she WILL write nulls into it. π
mwah, that's the whole page. this gem came to you from the lovely folks at Simple Directmedia Layer, and this particular copy is chillin' at version SDL 3.4.18. go tokenize something. slay. β¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms