SDL_uitoa(3)

πŸ’– SDL_uitoa(3) πŸ’–

okay so bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where we turn numbers into glow-up strings. this one's called SDL_uitoa and it's giving "unsigned int, but make it text" ✨


🌸 NAME 🌸

SDL_uitoa β€” Convert an unsigned 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_uitoa(unsigned int value, char *str, int radix);

like look at her. three args, zero drama. iconic.


πŸ¦‹ DESCRIPTION πŸ¦‹

so the way this works is you have to tell her what radix to use for the string format, no skipping that part. say 10 and you get a decimal number, 16 and boom, hexadecimal, etc. the radix must be in the range of 2 to 36. that's the whole range, don't try to be cute and go outside it.

⚠️ NOT ME ABOUT TO RUIN THE VIBE BUT β€” this function will overflow a buffer if str is not large enough to hold the output! like literally, she does not check, she does not clamp, she just writes. 😭

if you want the safe route (and honestly, slay), it may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. otherwise, it doesn't hurt to allocate much more space than you expect to use β€” and don't forget null terminator bytes, etc. those little \0 besties are non-negotiable fr fr.


🫢 FUNCTION PARAMETERS 🫢

  • value β€” the unsigned integer to convert. this is the number getting its string era πŸ’«
  • str β€” the buffer to write the string into. your responsibility, your problem, allocate generously πŸ₯²
  • radix β€” the radix to use for string generation. 2 to 36, remember 🌈

⭐ RETURN VALUE ⭐

Returns str. that's it. she hands you back your own buffer, all dressed up. πŸ’–


🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread. yes bestie, any thread, all the threads, go off πŸ‘‘


🌈 AVAILABILITY 🌈

This function is available since SDL 3.2.0. so if you're on something older... girl. upgrade. πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ

the whole conversion friend group, go say hi πŸ“


and that's the page!! brought to you by Simple Directmedia Layer, version SDL 3.4.18, SDL_uitoa(3) β€” stay converted, stay safe, allocate more than you think you need, mwah πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from