uvszprintf(3alleg4)

✨ uvszprintf ✨

okay bestie, this one lives in the Allegro manual, section 3alleg4 β€” it's uvszprintf, and it's giving "I write your formatted text into a buffer but I need you to hand me the va_list yourself" energy. πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro.h>

int uvszprintf(char *buf, int size, const char *format, va_list args);

πŸ’– DESCRIPTION πŸ’–

So this is literally like uszprintf(), except instead of passing the variable arguments themselves, you pass the variable argument list directly. same vibes, different delivery method. πŸŽ€

Here's the whole thing in action, no cap:

#include <stdarg.h>

void log_message(const char *format, ...)
{
   char buffer[100];
   va_list parameters;

   va_start(parameters, format);
   uvszprintf(buffer, sizeof(buffer), format, parameters);
   va_end(parameters);

   append_buffer_to_logfile(log_name, buffer);
   send_buffer_to_other_networked_players(multicast_ip, buffer);
   and_also_print_it_on_the_screen(cool_font, buffer);
}

void some_other_function(void)
{
   log_message("Hello %s, are you %d years old?\n", "Dave", 25);
}

see how log_message takes the ... and then forwards parameters straight into uvszprintf? that's the whole point, bestie. the wrapper function stays a wrapper function. πŸ‘‘


🌈 RETURN VALUE 🌈

It returns the number of characters that would have been written if nothing got truncated β€” exactly like uvsprintf does β€” and nope, that count does not include the terminating null character. πŸ¦‹

heads up: "would have been written" is doing a lot of work in that sentence. truncation doesn't change the return value, so don't go using it as "how many chars actually landed in my buffer". πŸ™ˆ

⭐ SEE ALSO ⭐


mwah πŸ’– that's the whole page. this lil icon shipped with Allegro, version 4.4.3 β€” so go forth, pass your va_list around responsibly, and slay. periodt. 🫢✨