Skip to content

<snprintf.h>

Bounded formatted output.

#include <snprintf.h>

Functions

snprintf

int snprintf(char *buf, size_t size, const char *fmt,...);

Formats into a buffer, C99-style.

Writes at most size - 1 characters and a NUL. With size 0 nothing is written. Safe to nest: each call keeps its own state.

Parameter Direction Description
buf out Output buffer.
size in Size of buf.
fmt in printf format.
... in Arguments.

Returns: The length the full output would have, excluding the NUL, even when truncated.

vsnprintf

int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);

snprintf() taking a va_list.

Parameter Direction Description
buf out Output buffer.
size in Size of buf.
fmt in printf format.
args in Arguments.

Returns: As snprintf().