ustrtol(3alleg4)
β¨ ustrtol β bestie, we're turning strings into integers β¨
okay so this is ustrtol from the Allegro manual (yes, the 3alleg4 girlies know) β it's a little function from the Allegro game programming library, and she is so useful. let's get into it π
πΈ SYNOPSIS πΈ
#include <allegro.h>
long ustrtol(const char *s, char **endp, int base);
that's it. that's the whole vibe. three little args and she converts for you π«Ά
π DESCRIPTION π
so here's the tea: this function converts the initial part of s to a signed integer. and if endp is not a NULL pointer, she sets *endp to point at the first unused character β like, "here's where I stopped reading, bestie, the rest is yours" π
the base argument tells her what base those digits (or letters, no judgement) should be treated as. it's giving very flexible, very inclusive π¦
and here's the β¨iconicβ¨ part β if base is zero, she's a detective: she looks for 0x, 0X, or 0 as the first part of the string, and sets the base used to 16, 16, or 8 if she finds one. no cap. and the default base is 10 if none of those prefixes show up. periodt π
example time, because we love a demo:
char *endp, *string = "456.203 askdfg";
int number = ustrtol(string, &endp, 10);
look at her go π₯Ή
π RETURN VALUE π
returns the string converted as a value of type long int. main character energy fr fr π
but β and listen closely β if nothing was converted, she returns zero with *endp pointing to the beginning of s. so like, she didn't even move. that's your vibe check right there π
π SEE ALSO π
go read those too, they're all part of the same friend group π«Άβ¨
and that's the whole page, bestie!! this one came from the Allegro manual, version 4.4.3, and yeah β ustrtol(3alleg4) is her full government name. go forth and parse responsibly π§ππΈ
π¦ 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