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. between 2 and 36, 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