ustrtol(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

✨ ustrtol(3) ✨

okay so bestie, welcome to ustrtol, straight outta the Allegro manual β€” aka the Allegro game programming library πŸ’–. she's a lil string-to-integer converter and she's lowkey iconic for it.


🌸 NAME 🌸

ustrtol β€” converts a string into an integer. part of the Allegro game programming library, no cap πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

long ustrtol(const char *s, char **endp, int base);

✨ DESCRIPTION ✨

so what she does is: she takes the initial part of s and turns it into a signed integer, and if endp is not a NULL pointer, she sets *endp to point at the first unused character β€” like the first one she didn't eat πŸ“. the leftovers, basically.

the base argument is the vibe check for what base those digits (or letters, bestie, letters are digits in high bases, it's giving hex energy) should be treated as πŸ”₯.

and here's the cute part: if base is zero, she figures out the base herself by peeking at the first part of the string for a 0x, 0X, or 0 prefix, and sets the base to 16, 16, or 8 if she finds one πŸ‘‘. if none of those prefixes show up, the default base is 10. she just knows. main character intuition fr fr.

example time, periodt:

char *endp, *string = "456.203 askdfg";
int number = ustrtol(string, &endp, 10);

πŸ’– RETURN VALUE πŸ’–

she returns the string converted as a value of type long int ✨.

but if nothing was converted? she returns zero and *endp points to the beginning of s β€” like, nothing happened, we're back where we started, awkward 😭.


🫢 SEE ALSO 🫢


and that's the whole page, bestie 🌈. this was Allegro, version 4.4.3 β€” the ustrtol(3) era. slay, go convert some strings πŸ’œπŸŽ€

πŸ“¦ where this page comes from