SDL School

API reference / Files, memory, and strings

SDL_snprintf

Function, SDL3

Writes formatted text into an array, as snprintf does. It never writes past the size that you give.

Declaration

#include <SDL3/SDL.h>

int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);

Parameters

textThe destination array.
maxlenThe size of the array in bytes.
fmtA format string.
...The values for the format string.

Return value

The length of the full text. A result of maxlen or more means that the text was cut.

Example

Draw text
SDL_snprintf(text, sizeof(text), "Clicks: %d", clicks);

See this code run in Draw text. Download the full program (.zip)

In SDL2

The name is the same.

See also