wprintf(3)
π wprintf(3) β the wide-character glow-up of printf π
okay bestie, so this is wprintf, part of the Library Functions Manual, living in the Standard C library (libc, -lc). it's formatted wide-character output and honestly? it ate. let me walk you through it π«Ά
β¨ NAME β¨
wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf β formatted wide-character output conversion πΈ
π LIBRARY π
Standard C library (libc, -lc)
π SYNOPSIS π
#include <stdio.h>
#include <wchar.h>
int wprintf(const wchar_t *restrict format, ...);
int fwprintf(FILE *restrict stream,
const wchar_t *restrict format, ...);
int swprintf(size_t n;
wchar_t wcs[restrict n], size_t n,
const wchar_t *restrict format, ...);
int vwprintf(const wchar_t *restrict format, va_list args);
int vfwprintf(FILE *restrict stream,
const wchar_t *restrict format, va_list args);
int vswprintf(size_t n;
wchar_t wcs[restrict n], size_t n,
const wchar_t *restrict format, va_list args);
lowkey yes,swprintfandvswprintfhave that funkysize_t n;declared inside the parameter list. that's not a typo, that's just how they wrote it in the manpage. periodt π
π§ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
all functions shown above:
_XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
|| _POSIX_C_SOURCE >= 200112L
π¦ DESCRIPTION π¦
The wprintf() family is literally the wide-character equivalent of the printf(3) family. same energy, but it performs formatted output of wide characters β¨
The wprintf() and vwprintf() functions do wide-character output to stdout. heads up: stdout must not be byte oriented β see fwide(3) for more info, no cap.
The fwprintf() and vfwprintf() functions do wide-character output to stream. and yes, stream must not be byte oriented either β see fwide(3).
The swprintf() and vswprintf() functions do wide-character output to an array of wide characters. bestie, you (the programmer, the main character) have to make sure there's room for at least n wide characters at wcs. don't skip that part π
These functions are like printf(3), vprintf(3), fprintf(3), vfprintf(3), sprintf(3), and vsprintf(3) β except for these lil differences:
- The
formatstring is a wide-character string. π - The output consists of wide characters, not bytes.
swprintf()andvswprintf()take annargument;sprintf(3)andvsprintf(3)do not. (and yes,snprintf(3)andvsnprintf(3)do take annargument, but those functions do not return -1 upon buffer overflow on Linux β so like, don't assume they're twins. they're not. π)
The way the conversion characters c and s are treated is different:
cβ if nolmodifier is present, theintargument gets converted to a wide character by a call to thebtowc(3)function, and the resulting wide character is written. If anlmodifier is present, thewint_t(wide character) argument is written.sβ if nolmodifier is present: theconst char *argument is expected to be a pointer to an array of character type (pointer to a string) containing a multibyte character sequence beginning in the initial shift state. Characters from the array get converted to wide characters (each by a call to thembrtowc(3)function, with a conversion state starting in the initial state before the first byte). The resulting wide characters are written up to β but not including β the terminating null wide character (L'\0'). If a precision is specified, no more wide characters than that number are written. π note that the precision determines the number of wide characters written, not the number of bytes or screen positions. The array must contain a terminating null byte ('\0'), unless a precision is given and it's so small that the number of converted wide characters reaches it before the end of the array is reached.
If an l modifier is present: the const wchar_t * argument is expected to be a pointer to an array of wide characters. Wide characters from the array are written up to β but not including β a terminating null wide character. If a precision is specified, no more than the number specified are written. The array must contain a terminating null wide character, unless a precision is given and it's smaller than or equal to the number of wide characters in the array. π
π₯ RETURN VALUE π₯
The functions return the number of wide characters written, excluding the terminating null wide character in the case of swprintf() and vswprintf(). π
On error, -1 is returned, and errno is set to indicate the error. π
π ERRORS π
See write(2) and putwc(3). And in addition, this error may occur:
EOVERFLOWβ the value to be returned is greater thanINT_MAX. (it's giving overflow, it's giving too much.)
The fwprintf() and wprintf() functions may additionally fail if:
ENOMEMβ insufficient storage space is available. π«
β ATTRIBUTES β
For an explanation of the terms used in this section, see attributes(7).
- Interface:
wprintf(),fwprintf(),swprintf(),vwprintf(),vfwprintf(),vswprintf()- Attribute: Thread safety
- Value:
MT-Safe locale
so yeah, all six of them are MT-Safe locale β same energy across the whole squad π
π STANDARDS π
C11, POSIX.1-2008. iconic, we love a standardized queen β¨
π°οΈ HISTORY π°οΈ
POSIX.1-2001, C99. she's been around, she's got lore πΈ
π NOTES π
The behavior of wprintf() et al. depends on the LC_CTYPE category of the current locale. π
If the format string contains non-ASCII wide characters, the program will work correctly only if the LC_CTYPE category of the current locale at run time is the same as the LC_CTYPE category of the current locale at compile time. this is the important bit, bestie: it's because the wchar_t representation is platform- and locale-dependent. (glibc represents wide characters using their Unicode (ISO/IEC 10646) code point, but other platforms don't do this. also, the use of C99 universal character names of the form \unnnn does not solve this problem. π)
So, in internationalized programs, the format string should consist of ASCII wide characters only, or should be constructed at run time in an internationalized way (e.g., using gettext(3) or iconv(3), followed by mbstowcs(3)). π«Ά do it right, you'll thank yourself later.
π SEE ALSO π
fprintf(3), fputwc(3), fwide(3), printf(3), snprintf(3)
<div align="center">
πΈ that's the whole page, babes πΈ
this one's from Linux man-pages 6.20, dated 2026-02-08, and it's the wprintf(3) page π go forth and format your wide characters responsibly, ily π«Άβ¨
</div>
π¦ 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