wprintf

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf - ワイド文字を フォーマットして出力する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#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);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

上記の全ての関数:

    _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
        || _POSIX_C_SOURCE >= 200112L
 

説明

wprintf() ファミリーの関数は printf(3) ファミリーの関数の ワイド文字版である。これらはワイド文字をフォーマットして出力する。

wprintf() と vwprintf() 関数は stdout に出力を行なう。 stdout がバイト単位入出力であってはいけない。より詳しい説明は fwide(3) を参照すること。

fwprintf() と vfwprintf() 関数は stream にワイド文字出力 を行なう。 stream がバイト単位入出力であってはいけない。 より詳しい説明は fwide(3) を参照すること。

The swprintf() and vswprintf() functions perform wide-character output to an array of wide characters. The programmer must ensure that there is room for at least n wide characters at wcs.

これらの関数は printf(3), vprintf(3), fprintf(3), vfprintf(3), sprintf(3), vsprintf(3) 関数に似ているが以下の 点で異っている。

•
format がワイド文字列で与えられる。
•
出力がバイトではなくワイド文字で構成される。
•
swprintf() and vswprintf() take a n argument, sprintf(3) and vsprintf(3) do not. (snprintf(3) and vsnprintf(3) take a n argument, but these functions do not return -1 upon buffer overflow on Linux.)

c と s 変換文字の扱いが異っている:

c
もし l 修飾子が存在しない場合は int 引数は btowc(3) 関数によってワイド文字に変換される。そして結果のワイド文字が出力される。 l 修飾子が存在する場合は wint_t (ワイド文字)引数が出力される。
s
If no l modifier is present: the const 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 are converted to wide characters (each by a call to the mbrtowc(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 the number specified 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 is 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 is smaller than or equal to the number of wide characters in the array.
 

返り値

The functions return the number of wide characters written, excluding the terminating null wide character in case of the functions swprintf() and vswprintf(). On error, -1 is returned, and errno is set to indicate the error.  

エラー

See write(2) and putwc(3). In addition, the following error may occur:
EOVERFLOW
The value to be returned is greater than INT_MAX.

The fwprintf() and wprintf() functions may fail additionally if:

ENOMEM
Insufficient storage space is available.
 

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
wprintf(), fwprintf(), swprintf(), vwprintf(), vfwprintf(), vswprintf() Thread safetyMT-Safe locale
 

標準規格

C11, POSIX.1-2008.  

歴史

POSIX.1-2001, C99.  

注意

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 because the wchar_t representation is platform- and locale-dependent. (The 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.) Therefore, 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)).  

関連項目

fprintf(3), fputwc(3), fwide(3), printf(3), snprintf(3)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
属性
標準規格
歴史
注意
関連項目

This document was created by man2html, using the manual pages.