SDL_strtol(3)

✨ SDL_strtol ✨

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, page SDL_strtol(3). this one is lowkey iconic and you're gonna eat it up πŸ’…


🌸 NAME 🌸

SDL_strtol β€” parse a long out of a string, fr fr.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_stdinc.h>

long SDL_strtol(const char *str, char **endp, int base);

πŸ’– DESCRIPTION πŸ’–

so here's the vibe. if str starts with whitespace, those whitespace characters get skipped before anything tries to parse the number. like, they're just not the moment, you know? 🫢

and if the parsed number doesn't fit inside a long?? it gets clamped to the minimum and maximum representable long values. no overflow drama, just vibes, it gets squished into range. periodt.


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • str β€” the null-terminated string you wanna read. Must not be NULL. like. do not. πŸ™ˆ
  • endp β€” if it's not NULL, the address of the first invalid character (aka the next character after the parsed number) gets written to this pointer. it's giving "here's where I stopped reading" ✨
  • base β€” the base of the integer you're reading. supported values are 0 and 2 to 36 inclusive. if it's 0, the base gets inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise). so smart, so intuitive, we love a self-aware base πŸ‘‘

⭐ RETURN VALUE ⭐

returns the parsed long. or 0 if no number could be parsed. that's it. that's the whole thing. 😭


🌈 THREAD SAFETY 🌈

it is safe to call this function from any thread. no cap. go wild, bestie. 🧚


πŸ‘‘ AVAILABILITY πŸ‘‘

this function is available since SDL 3.2.0. so if you're on something older... girl. upgrade. πŸ’€


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page, bestie πŸ“ this lil masterpiece lives in Simple Directmedia Layer, version SDL 3.4.18, dated SDL_strtol(3). go parse something gorgeous πŸ’œβœ¨

πŸ“¦ where this page comes from