ustrtok_r(3)
π ustrtok_r(3) π
okay so bestie, welcome to the Allegro manual β¨ this one's a lil function from the Allegro game programming library and honestly? she's giving "I can do it while other people are mid-sentence" energy. main character behavior fr fr π
β¨ NAME β¨
ustrtok_r β the reentrant function that pulls tokens out of a string, brought to you by the Allegro game programming library. π
π¦ SYNOPSIS π¦
#include <allegro.h>
char *ustrtok_r(char *s, const char *set, char **last);
πΈ DESCRIPTION πΈ
So ustrtok_r is literally the reentrant version of ustrtok π and the glow-up here is the last parameter, no cap.
That last guy is what keeps track of where the parsing is up to. It must be a pointer to a char * variable that you allocate, and it has to stay the same while you're parsing the same string. like, don't be switching it up mid-parse, that's not the vibe. π
Example time, bestie:
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);
see how after the first call we pass NULL for s? yeah. that's her thing. once you're in the loop, the string lives in last's head, not yours. π§ β¨
π RETURN VALUE π
She returns a pointer to the token, or NULL if there are no more tokens to find. periodt. π«Ά
And here's the cute part: once you get that NULL back, you can free the memory that last is pointing to. it's done, it's retired, it ate and left no crumbs. π
π SEE ALSO π
Allegro β version 4.4.3 π
and that's the whole page bestie, mwah, go parse some strings, ily πβ¨π¦
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms