sprintf(3)
π sprintf(3) β string print formatted π
okay bestie, sit down, hydrate, and let me tell you about sprintf and vsprintf β two functions from the Library Functions Manual that are giving iconic but slightly feral energy. β¨ They live in the standard C library, ngl.
π LIBRARY π
Standard C library (libc, -lc) π«Ά
π SYNOPSIS π
#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
(yes, the macro list really does say snprintf() and vsnprintf() β I'm just the messenger, bestie π
)
πΈ DESCRIPTION πΈ
So these two? They're literally equivalent to snprintf(3) and vsnprintf(3)β¦ except there's no check for buffer overrun performed. None. Zero. Not a vibe check in sight. π (peep BUGS below, it's important, iykyk).
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7).
sprintf(),vsprintf()β Thread safety:MT-Safe locale
β STANDARDS β
C11, POSIX.1-2008. queen behavior, fr fr π
π¦ HISTORY π¦
C89, POSIX.1-2001. she's been around, she's seen things πΈ
π BUGS π
See printf(3).
π sprintf(), vsprintf()
Because sprintf() and vsprintf() assume an arbitrarily long string, callers must be careful not to overflow the actual space β and honestly? this is often impossible to assure. π«
Also note that the length of the strings produced is locale-dependent and difficult to predict. so like. unpredictable AND dangerous. not the duo we wanted. π
Usesnprintf()andvsnprintf()instead (orasprintf(3)andvasprintf(3)). periodt. protect your buffers, protect your peace. π«Ά
π SEE ALSO π
mwah π that's the whole page, bestie β brought to you by Linux man-pages 6.20, dated 2025-12-07. go forth and not overflow your buffers β¨ππ¦
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms