SDL_itoa(3)
π SDL_itoa β bestie edition β¨
okay so this is SDL_itoa(3), a lil function from the SDL3 FUNCTIONS crew, and it's literally here to turn your integers into cute lil strings π
β¨ NAME β¨
SDL_itoa β Convert an integer into a string. that's it, that's the whole job, and she does it flawlessly π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_stdinc.h>
char * SDL_itoa(int value, char *str, int radix);
π¦ DESCRIPTION π¦
so the vibe here is that you gotta tell her what radix you want for the string format, no guessing, she's not a mind reader bestie π
- radix
10β you get a decimal number - radix
16β you get hexadecimal - etc etc, you get the picture
and the radix must be in the range of 2 to 36. no cap. outside that range is not the move π
β οΈ NOT ME FORGETTING TO WARN YOU: this function will overflow a buffer if str is not large enough to hold the output! it's giving chaos, it's giving undefined, it's giving π
so if you want to be a responsible main character, it may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer π«Ά
otherwise, honestly? it doesn't hurt to allocate much more space than you expect to use. and don't forget possible negative signs, null terminator bytes, etc etc etc. the little guys add up, fr fr πΈ
π FUNCTION PARAMETERS π
valueβ the integer to convert. the star of the show, the moment, the icon πstrβ the buffer to write the string into. she's the vessel, she's the canvas, she's gotta be big enough πradixβ the radix to use for string generation. between2and36, remember? β
π RETURN VALUE π
Returns str. yeah, she just hands you back the same buffer you gave her. iconic behavior, no notes π
π THREAD SAFETY π
It is safe to call this function from any thread. multitasking queen, we love to see it π§
β AVAILABILITY β
This function is available since SDL 3.2.0. so if you're on something older... not me, not you, we don't know her π
π SEE ALSO π
go read the whole fam, they're all serving β¨
k that's the whole page bestie, go forth and convert your ints responsibly π
this lil masterpiece came from the Simple Directmedia Layer girlies, running SDL 3.4.18, and yes she's literally SDL_itoa(3) β mwah, bye ππ
β¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms