ustrtok_r(3alleg4)
π ustrtok_r β the Allegro manual, but make it cute β¨
okay bestie, welcome to ustrtok_r(3alleg4), aka the Allegro game programming library page for the reentrant token-grabber. she's giving "I split strings but I don't forget where I was" and honestly? iconic. π
β¨ NAME β¨
ustrtok_r β a reentrant function that pulls tokens out of a string. part of the Allegro game programming library. π
π¦ SYNOPSIS π¦
#include <allegro.h>
char *ustrtok_r(char *s, const char *set, char **last);
πΈ DESCRIPTION πΈ
so this is the reentrant version of ustrtok. the glow-up is the last parameter: she's the one holding the receipts on where the parsing is up to. π
here's the thing though β last has to be a pointer to a char * variable that you allocate yourself, and it has to stay the same variable the whole time you're parsing the same string. no swapping her out mid-parse, bestie, she's the memory of the operation. π§ β¨
example time, look at her go:
char *word, *last;
char string[]="some-words with dashes";
char *temp = ustrdup(string);
word = ustrtok_r(string, " -", &last);
while (word) {
allegro_message("Found `%s'\n", word);
word = ustrtok_r(NULL, " -", &last);
}
free(temp);
the way she just keeps passing NULL in and letting last do the heavy liftingβ¦ that's the whole vibe. π«Ά
π RETURN VALUE π
she returns a pointer to the token, or NULL if there are no more tokens left to find. π
and here's a lil gift: once NULL comes back, you can go ahead and free the memory that last points to. clean up after yourself, main character. π
β¨
π₯ SEE ALSO π₯
okay that's the whole page, bestie, no cap. this was Allegro version 4.4.3, and the manual name is ustrtok_r(3alleg4) in case you need to cite her. mwah, go tokenize something cute ππβ¨
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms