sprintf(3) Library Functions Manual sprintf(3)

sprintf, vsprintf - string print formatted

Standard C library (libc-lc)

#include <stdio.h>
int sprintf(char *restrict str,
            const char *restrict format, ...);
int vsprintf(char *restrict str,
            const char *restrict format, va_list ap);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

snprintf(), vsnprintf():



    _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE

        || /* glibc <= 2.19: */ _BSD_SOURCE

These functions are equivalent to snprintf(3) and vsnprintf(3), except that no check for buffer overrun is performed (see BUGS below).

For an explanation of the terms used in this section, see attributes(7).

Interface Attribute Value
sprintf (), vsprintf () Thread safety MT-Safe locale

C11, POSIX.1-2008.

C89, POSIX.1-2001.

See printf(3).

Because sprintf() and vsprintf() assume an arbitrarily long string, callers must be careful not to overflow the actual space; this is often impossible to assure. Note that the length of the strings produced is locale-dependent and difficult to predict. Use snprintf() and vsnprintf() instead (or asprintf(3) and vasprintf(3)).

asprintf(3), snprintf(3)

2025-12-07 Linux man-pages (unreleased)

Different Versions of this Page: