?
本文檔使用 php中文網手冊 發(fā)布
在頭文件<wchar.h>中定義 | ||
---|---|---|
(1) | ||
int wprintf(const wchar_t * format,...); | (自C95以來)(直到C99) | |
int wprintf(const wchar_t * restrict format,...); | (自C99以來) | |
(2) | ||
int fwprintf(FILE * stream,const wchar_t * format,...); | (自C95以來)(直到C99) | |
int fwprintf(FILE * restrict stream,const wchar_t * restrict format,...); | (自C99以來) | |
(3) | ||
int swprintf(wchar_t * buffer,size_t bufsz,const wchar_t * format,...); | (自C95以來)(直到C99) | |
int swprintf(wchar_t * restrict buffer,size_t bufsz,const wchar_t * restrict format,...); | (自C99以來) | |
int wprintf_s(const wchar_t * restrict format,...); | (4) | (自C11以來) |
int fwprintf_s(FILE * restrict stream,const wchar_t * restrict format,...); | (5) | (自C11以來) |
int swprintf_s(wchar_t * restrict buffer,rsize_t bufsz,const wchar_t * restrict format,...); | (6) | (自C11以來) |
int snwprintf_s(wchar_t * restrict s,rsize_t n,const wchar_t * restrict format,...); | (7) | (自C11以來) |
從給定的位置加載數據,將它們轉換為寬字符串等值并將結果寫入各種接收器。
1)將結果寫入stdout
。
2)將結果寫入文件流stream
。
3)如果bufsz
大于零,則將結果寫入寬字符串buffer
。最bufsz-1
寬字符后面跟著空寬字符。如果bufsz
為零,則不會寫入任何內容(并且buffer
可能是空指針),但返回值(將寫入的寬字符數)仍然會計算并返回。
4-6)與(1-3)相同,但在運行時檢測到以下錯誤并調用當前安裝的約束處理函數:
轉換說明符%n
存在于format
任何對應的參數%s
都是空指針
format
或者buffer
是空指針
bufsz
是零或大于 RSIZE_MAX/sizeof(wchar_t)
編碼錯誤出現在任何字符串和字符轉換說明符中
(僅限于swprintf_s
)要寫入的寬字符數(包括null)將超過bufsz
。
7)與(6)相同,只是它會截斷結果以適應s所指向的數組。由于所有的邊界檢查功能,wprintf_s
,wfprintf_s
,和wsprintf_s
僅保證可供如果__STDC_LIB_EXT1__
由實現所定義,并且如果用戶定義__STDC_WANT_LIB_EXT1__
的整數常數1
,包括之前<stdio.h>
。
流 | - | 輸出文件流寫入 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
緩沖 | - | 指向要寫入的寬字符字符串的指針 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bufsz | - | 最多可以寫入bufsz-1寬字符,加上空終止符 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
格式 | - | 指向以空字符結尾的寬字符串的指針,指定如何解釋數據。格式字符串由普通的寬字符(%除外)組成,它們被不變地復制到輸出流中,以及轉換規(guī)范。每個轉換規(guī)范具有以下格式:介紹%字符(可選)一個或多個標志,用于修改轉換的行為: - :轉換結果在字段內左對齊(默認情況下,它是右對齊的)+ :帶符號轉換的符號總是作為轉換結果的前綴(默認情況下,只有當結果為負時,結果才以負值開頭)space:如果帶符號轉換的結果不是以符號字符開頭,或者是空的,空間是預先考慮的結果。如果存在+標志,則忽略它。#:執(zhí)行轉換的替代形式。請參閱下表以了解確切的效果,否則行為未定義。0:對于整數和浮點數轉換,前導零用于填充字段而不是空格字符。對于整數,如果明確指定了精度,它將被忽略。對于使用此標志的其他轉換會導致未定義的行為。如果 - 標志存在,它將被忽略。(可選)整數值或*指定最小字段寬度。如果需要,結果會填充空格字符(默認情況下),右側對齊時填充空白字符,左側填充右側填充。在使用*的情況下,寬度由類型為int的附加參數指定。如果參數的值是負值,那么結果是指定 - 標志和正字段寬度。(注意:這是最小寬度:該值從不被截斷。)(可選)。后跟整數或*,或者兩者都不指定轉換的精度。在使用*的情況下,精度由類型為int的附加參數指定。如果這個參數的值是負數,它將被忽略。如果既不使用數字也不使用*,則精度取為零。請參閱下表以了解精確度的確切影響。(可選)長度修飾符,用于指定參數轉換格式說明符的大小以下格式說明符可用:轉換說明符說明參數類型長度修飾符hh(C99)。h(無)ll(C99)。j(C99)。z(C99)。t(C99)。L%寫文字%。完整的轉換規(guī)范必須是%%。不適用不適用不適用不適用不適用不適用不適用不適用不適用單個字符。該參數首先轉換為wchar_t,就好像通過調用btowc一樣。如果使用l修飾符,則首先將wint_t參數轉換為wchar_t。N / AN / A int wint_t N / AN / AN / AN / AN / A s寫入字符串參數必須是一個指向包含多字節(jié)字符序列的字符數組的初始元素的指針,該字符序列從初始轉換狀態(tài)開始,被轉換為寬字符數組,就像通過調用mbrtowc以零初始化轉換狀態(tài)一樣。Precision指定要寫入的最大寬字符數。如果未指定Precision,則將每個寬字符寫入并不包括第一個空終止符。如果使用l說明符,參數必須是指向wchar_t數組的初始元素的指針。N / AN / A char * wchar_t * N / AN / AN / AN / AN / A di將有符號整數轉換為十進制表示形式-dddd。精度指定出現的最小位數。默認精度為1.如果轉換值和精度均為0,則轉換不會生成任何字符。signed char short int long long long intmax_t signed size_t ptrdiff_t不適用o將無符號整數轉換為八進制表示oooo。精度指定出現的最小位數。默認精度為1.如果轉換值和精度均為0,則轉換不會生成任何字符。在替代實現中,如果需要,可以增加精度以寫入一個前導零。在這種情況下,如果轉換值和精度均為0,則寫入單個0。unsigned char unsigned short unsigned int unsigned long unsigned long long uintmax_t size_t ptrdiff_t的無符號版本不適用x X將無符號整數轉換為十六進制表示形式hhhh。對于x轉換字母abcdef被使用。對于X轉換字母使用ABCDEF。精度指定出現的最小位數。默認精度為1.如果轉換值和精度均為0,則轉換不會生成任何字符。在替代實現中,如果轉換后的值為非零值,則0x或0X將作為結果的前綴。不適用u將無符號整數轉換為十進制表示形式dddd。精度指定出現的最小位數。默認精度為1。如果轉換值和精度均為0,則轉換不會生成字符。N / A f F將浮點數轉換為樣式-ddd.ddd中的十進制表示法。精度指定小數點后面出現的最小位數。默認精度為6.在替代實現中,即使沒有數字跟隨,小數點字符也會被寫入。對于無限和非數字轉換風格,請參閱注釋。N / AN / A double double(C99)N / AN / AN / AN / A long double e E將浮點數轉換為十進制指數表示法。對于e轉換樣式,使用-d.ddde±dd。對于E轉換樣式,使用-d.dddE±dd。指數至少包含兩位數字,只有在必要時才使用更多數字。如果該值為0,則指數也為0。精度指定小數點后面出現的最小位數。默認精度為6.在替代實現中,即使沒有數字跟隨,小數點字符也會被寫入。對于無限和非數字轉換風格,請參閱注釋。不適用不適用不適用不適用不適用不適用(C99)。將浮點數轉換為十六進制指數表示法。對于轉換類型,使用-0xh.hhhp±d。對于A轉換樣式,使用-0Xh.hhhP±d。如果參數不是標準化的浮點值,則第一個十六進制數字為0。如果該值為0,則指數也為0。精度指定小數點后面出現的最小位數。默認精度足以精確表示值。在替代實現中,即使沒有數字跟隨,小數點字符也會被寫入。對于無限和非數字轉換風格,請參閱注釋。不可用/不可用/不可用/不可用/ g G根據值和精度將浮點數轉換為十進制或十進制指數符號。對于使用樣式e或f的g轉換樣式轉換將被執(zhí)行。對于G轉換樣式,將使用樣式E或F進行轉換。假設P等于非零的精度,如果未指定精度,則等于6;如果精度為0,則等于1。然后,如果具有樣式E的轉換將具有X的指數:如果P> X≥-4,則轉換具有樣式f或F和精度P-1-X。否則,轉換具有樣式e或E以及精度P - 1。除非請求替代表示,否則尾隨零將被刪除,如果沒有剩余小數部分,小數點字符也會被刪除。對于無限和非數字轉換風格,請參閱注釋。不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用不適用 結果寫入參數指向的值。規(guī)范可能不包含任何標志,字段寬度或精度。signed char * short * int * long * long long * intmax_t * signed size_t * ptrdiff_t * N / A p寫一個實現定義的字符序列來定義一個指針。不適用不適用不適用不適用不適用不適用不適用浮點轉換函數將無窮大轉換為inf或無窮大。使用哪一個是實現定義的。非數字轉換為南或南(char_sequence)。使用哪一個是實現定義的。轉換F,E,G,A代替輸出INF,INFINITY,NAN。盡管%c需要int參數,但因為在調用可變參數函數時發(fā)生整數提升,所以傳遞char是安全的。固定寬度字符類型(int8_t等)的正確轉換規(guī)范在標頭<inttypes.h>中定義(盡管PRIdMAX,PRIuMAX等與%jd,%ju等同義)。內存寫入轉換說明符%n是格式字符串依賴用戶輸入并且不受邊界檢查的printf_s系列函數支持的安全漏洞的常見目標。每個轉換說明符的操作之后都有一個序列點; 這允許將多個%n結果存儲在相同的變量中,或者,作為邊緣情況,在相同的調用中打印由早先的%n修改的字符串。如果轉換規(guī)范無效,則行為未定義。 | Conversion specifier | Explanation | Argument type | length modifier | hh (C99). | h | (none) | l | ll (C99). | j (C99). | z (C99). | t (C99). | L | % | writes literal %. The full conversion specification must be %%. | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | c | writes a single character. The argument is first converted to wchar_t as if by calling btowc. If the l modifier is used, the wint_t argument is first converted to wchar_t. | N/A | N/A | int | wint_t | N/A | N/A | N/A | N/A | N/A | s | writes a character string The argument must be a pointer to the initial element of a character array containing a multibyte character sequence beginning in the initial shift state, which is converted to wide character array as if by a call to mbrtowc with zero-initialized conversion state. Precision specifies the maximum number of wide characters to be written. If Precision is not specified, writes every wide characters up to and not including the first null terminator. If the l specifier is used, the argument must be a pointer to the initial element of an array of wchar_t. | N/A | N/A | char* | wchar_t* | N/A | N/A | N/A | N/A | N/A | d i | converts a signed integer into decimal representation -dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | signed char | short | int | long | long long | intmax_t | signed size_t | ptrdiff_t | N/A | o | converts a unsigned integer into octal representation oooo. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation precision is increased if necessary, to write one leading zero. In that case if both the converted value and the precision are 0, single 0 is written. | unsigned char | unsigned short | unsigned int | unsigned long | unsigned long long | uintmax_t | size_t | unsigned version of ptrdiff_t | N/A | x X | converts an unsigned integer into hexadecimal representation hhhh. For the x conversion letters abcdef are used. For the X conversion letters ABCDEF are used. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation 0x or 0X is prefixed to results if the converted value is nonzero. | N/A | u | converts an unsigned integer into decimal representation dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | N/A | f F | converts floating-point number to the decimal notation in the style -ddd.ddd. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | double | double (C99) | N/A | N/A | N/A | N/A | long double | e E | converts floating-point number to the decimal exponent notation. For the e conversion style -d.ddde±dd is used. For the E conversion style -d.dddE±dd is used. The exponent contains at least two digits, more digits are used only if necessary. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | a A (C99). | converts floating-point number to the hexadecimal exponent notation. For the a conversion style -0xh.hhhp±d is used. For the A conversion style -0Xh.hhhP±d is used. The first hexadecimal digit is 0 if the argument is not a normalized floating point value. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is sufficient for exact representation of the value. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | g G | converts floating-point number to decimal or decimal exponent notation depending on the value and the precision. For the g conversion style conversion with style e or f will be performed. For the G conversion style conversion with style E or F will be performed. Let P equal the precision if nonzero, 6 if the precision is not specified, or 1 if the precision is 0. Then, if a conversion with style E would have an exponent of X: if P > X ≥ ?4, the conversion is with style f or F and precision P ? 1 ? X. otherwise, the conversion is with style e or E and precision P ? 1. Unless alternative representation is requested the trailing zeros are removed, also the decimal point character is removed if no fractional part is left. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | n | returns the number of characters written so far by this call to the function. The result is written to the value pointed to by the argument. The specification may not contain any flag, field width, or precision. | signed char* | short* | int* | long* | long long* | intmax_t* | signed size_t* | ptrdiff_t* | N/A | p | writes an implementation defined character sequence defining a pointer. | N/A | N/A | void* | N/A | N/A | N/A | N/A | N/A | N/A |
Conversion specifier | Explanation | Argument type | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
length modifier | hh (C99). | h | (none) | l | ll (C99). | j (C99). | z (C99). | t (C99). | L | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
% | writes literal %. The full conversion specification must be %%. | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
c | writes a single character. The argument is first converted to wchar_t as if by calling btowc. If the l modifier is used, the wint_t argument is first converted to wchar_t. | N/A | N/A | int | wint_t | N/A | N/A | N/A | N/A | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
s | writes a character string The argument must be a pointer to the initial element of a character array containing a multibyte character sequence beginning in the initial shift state, which is converted to wide character array as if by a call to mbrtowc with zero-initialized conversion state. Precision specifies the maximum number of wide characters to be written. If Precision is not specified, writes every wide characters up to and not including the first null terminator. If the l specifier is used, the argument must be a pointer to the initial element of an array of wchar_t. | N/A | N/A | char* | wchar_t* | N/A | N/A | N/A | N/A | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
d i | converts a signed integer into decimal representation -dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | signed char | short | int | long | long long | intmax_t | signed size_t | ptrdiff_t | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
o | converts a unsigned integer into octal representation oooo. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation precision is increased if necessary, to write one leading zero. In that case if both the converted value and the precision are 0, single 0 is written. | unsigned char | unsigned short | unsigned int | unsigned long | unsigned long long | uintmax_t | size_t | unsigned version of ptrdiff_t | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x X | converts an unsigned integer into hexadecimal representation hhhh. For the x conversion letters abcdef are used. For the X conversion letters ABCDEF are used. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. In the alternative implementation 0x or 0X is prefixed to results if the converted value is nonzero. | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
u | converts an unsigned integer into decimal representation dddd. Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are 0 the conversion results in no characters. | N/A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
f F | converts floating-point number to the decimal notation in the style -ddd.ddd. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | double | double (C99) | N/A | N/A | N/A | N/A | long double | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
e E | converts floating-point number to the decimal exponent notation. For the e conversion style -d.ddde±dd is used. For the E conversion style -d.dddE±dd is used. The exponent contains at least two digits, more digits are used only if necessary. If the value is 0, the exponent is also 0. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes. | N/A | N/A | N/A | N/A | N/A | N/A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
a A (C99). | 將浮點數轉換為十六進制指數表示法。對于轉換類型,使用-0xh.hhhp±d。對于A轉換樣式,使用-0Xh.hhhP±d。如果參數不是標準化的浮點值,則第一個十六進制數字為0。如果該值為0,則指數也為0。精度指定小數點后面出現的最小位數。默認精度足以精確表示值。在替代實現中,即使沒有數字跟隨它,也會寫入小數點字符。對于無窮大和非數字轉換風格,請參閱注釋。 | N / A | N / A | N / A | N / A | N / A | N / A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
g G | 根據值和精度將浮點數轉換為十進制或十進制指數符號。對于使用樣式e或f的g轉換樣式轉換將被執(zhí)行。對于G轉換樣式,將使用樣式E或F進行轉換。假設P等于非零的精度,如果未指定精度,則等于6;如果精度為0,則等于1。然后,如果具有樣式E的轉換將具有X的指數:如果P> X≥-4,則轉換具有樣式f或F和精度P-1-X。否則,轉換具有樣式e或E以及精度P - 1.除非要求替代表示,否則尾隨零將被刪除,如果沒有剩余小數部分,小數點字符也會被刪除。對于無窮大和非數字轉換風格,請參閱注釋。 | N / A | N / A | N / A | N / A | N / A | N / A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
? | 將此調用到目前為止寫入的字符數返回給該函數。結果寫入參數指向的值。規(guī)范可能不包含任何標志,字段寬度或精度。 | 簽名字符* | 短* | INT * | long* | 很長* | *將intmax_t | 簽名size_t * | ptrdiff_t的* | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
p | 寫一個實現定義的字符序列來定義一個指針。 | N / A | N / A | 無效* | N / A | N / A | N / A | N / A | N / A | N / A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
... | - | 指定要打印的數據的參數 |
介紹%
人物
(可選)一個或多個修改轉換行為的標志:
-
:轉換的結果在字段內左對齊(默認情況下它是右對齊的)
+
:帶符號轉換的符號總是預設為轉換結果的前綴(默認情況下結果前面為減號,僅當它為負值時)
空格:如果簽名轉換的結果不是以符號字符開頭,或者是空的,則空格會預設為結果。如果+
存在標志,則忽略它。
#
:執(zhí)行轉換的替代形式。請參閱下表以了解確切的效果,否則行為未定義。
0
:對于整數和浮點數轉換,前導零用于填充字段而不是空格字符。對于整數,如果明確指定了精度,它將被忽略。對于使用此標志的其他轉換會導致未定義的行為。如果-
存在標志,則忽略它。
(可選)整數值或*
指定最小字段寬度。如果需要,結果會填充空格字符(默認情況下),右側對齊時填充空白字符,左側填充右側填充。在使用的情況下*
,寬度由類型的附加參數指定int
。如果參數的值是負數,則結果是-
指定的標志和正的字段寬度。(注意:這是最小寬度:該值從不被截斷。)
(可選).
后面跟隨整數或者*
或者既不指定轉換的精度。在使用的情況下*
,精度由類型的附加參數指定int
。如果這個參數的值是負數,它將被忽略。如果既不使用數字也不*
使用,則精度取為零。請參閱下表以了解精確度的確切影響。
(可選)長度修飾符,用于指定參數的大小
轉換格式說明符
以下格式說明符可用:
Conversion
說明符說明參數類型長度修飾符 hh
(C99)。
h
(none) l
ll
(C99).
j
(C99).
z
(C99).
t
(C99).
L
%
寫文字%
。完整的轉換規(guī)范必須是%%
。N / AN / AN / AN / AN / AN / AN / AN / AN / A c
寫入單個字符。參數首先被轉換wchar_t
為仿佛通過調用btowc
。如果使用l修飾符,wint_t
則首先將參數轉換為wchar_t
。
N/A N/A int
wint_t
N / AN / AN / AN / AN / A s
寫入字符串參數必須是一個指向字符數組初始元素的指針,該字符數組包含一個多字節(jié)字符序列,從初始移位狀態(tài)開始,轉換為寬字符數組,如同通過調用mbrtowc
具有零初始化轉換狀態(tài)。Precision指定要寫入的最大寬字符數。如果未指定Precision,則將每個寬字符寫入并不包括第一個空終止符。如果使用l說明符,參數必須是指向數組的初始元素的指針wchar_t
。
N/A N/A char*
wchar_t*
N/A N/A N/A N/A N/A d
i
將有符號的整數轉換為十進制表示形式-dddd。 精度指定出現的最小位數。默認的精度是1
。
如果轉換后的值和精度都是0
沒有字符的轉換結果。
signed char
short
int
long
long long
intmax_t
簽 size_t
ptrdiff_t
N / A o
將無符號整數轉換為八進制表示oooo。 精度指定出現的最小位數。默認的精度是1
。如果轉換后的值和精度都是0
沒有字符的轉換結果。在替代實現中,如果需要,可以增加精度以寫入一個前導零。在這種情況下,如果轉換值和精度都是0
,0
寫入單個。
unsigned char
unsigned short
unsigned int
unsigned long
unsigned long long
uintmax_t
size_t
未簽名的版本 ptrdiff_t
N/A x
X
將無符號整數轉換為十六進制表示hhhh。使用x
轉換字母abcdef
。
使用X
轉換字母ABCDEF
。
精度指定出現的最小位數。默認的精度是1
。如果轉換后的值和精度都是0
沒有字符的轉換結果。在替代實現中, 0x
或者0X
如果轉換后的值不為零,則將其作為結果的前綴。
N / A u
將無符號整數轉換為十進制表示形式dddd。 精度指定出現的最小位數。默認的精度是1
。如果轉換后的值和精度都是0
沒有字符的轉換結果。
N/A f
F
將浮點數轉換為樣式-ddd.ddd中的小數表示法。 精度指定小數點后面出現的最小位數。默認的精度是6
。在替代實現中,即使沒有數字跟隨,小數點字符也會被寫入。對于無窮大和非數字轉換風格,請參閱注釋。
N/A N/A double
`double` (C99)
N/A N/A N/A N/A long double
`e`
E
將浮點數轉換為十進制指數符號。對于e
轉換樣式,使用-d.ddd e
±dd。
對于E
轉換樣式,使用-d.ddd E
±dd。
指數至少包含兩位數字,只有在必要時才使用更多數字。如果值是0
,指數也是0
。精度指定小數點后面出現的最小位數。默認的精度是6
。在替代實現中,即使沒有數字跟隨,小數點字符也會被寫入。對于無窮大和非數字轉換風格,請參閱注釋。
N/A N/A N/A N/A N/A N/A a
A
(C99).
將浮點數轉換為十六進制指數表示法。對于a
轉換樣式- 使用0x
h.hhh p
±d。
對于A
轉換樣式- 使用0X
h.hhh P
±d。
0
如果參數不是標準化的浮點值,則第一個十六進制數字是。如果值是0
,指數也是0
。精度指定小數點后面出現的最小位數。默認精度足以精確表示值。在替代實現中,即使沒有數字跟隨,小數點字符也會被寫入。對于無窮大和非數字轉換風格,請參閱注釋。
N/A N/A N/A N/A N/A N/A g
G
根據值和精度 將浮點數轉換為十進制或十進制指數符號。對于風格轉換的轉換與風格或將被執(zhí)行。gef
對于G
風格轉換的轉換與風格E
或F
將被執(zhí)行。
讓P
等于精度如果非零,6
如果沒有指定精度,或者1
如果精度是0
。然后,如果具有樣式的轉換E
將具有以下指數X
:
如果P> X≥-4,轉換是用式f
或F
和精度P - 1 - X。
否則,轉換采用樣式e
或E
精度P - 1。
除非請求替代表示,否則尾隨零將被刪除,如果沒有剩余小數部分,小數點字符也會被刪除。對于無窮大和非數字轉換風格,請參閱注釋。
不適用/不適用/不適用/不適用/ n
返回此函數迄今為止寫入的字符數。結果寫入參數指向的值。規(guī)范可能不包含任何標志,字段寬度或精度。
signed char*
short*
int*
long*
long long*
intmax_t*
signed size_t*
ptrdiff_t*
N / A p
寫入一個實現定義的字符序列來定義一個指針。不適用不適用不適用不適用不適用不適用 void*
浮點轉換函數將無窮大轉換為inf
或infinity
。使用哪一個是實現定義的。
非數字轉換為nan
或。使用哪一個是實現定義的。nan(char_sequence)
該轉換F
,E
,G
,A
輸出INF
,INFINITY
,NAN
來代替。
即使%c
需要int
參數,通過char
調用可變參數函數時發(fā)生的整數提升也是安全的。
對于固定寬度的字符類型(正確的轉換規(guī)格int8_t
<inttypes.h>還(雖然,等等)都在頭定義PRIdMAX
,PRIuMAX
等是同義詞%jd
,%ju
等)。
內存寫入轉換說明符%n
是安全漏洞的常見目標,其中格式字符串取決于用戶輸入,并且不受邊界檢查printf_s
函數族的支持。
每個轉換說明符的操作之后都有一個序列點; 這允許將多個%n
結果存儲在相同的變量中,或者作為邊緣情況,%n
在同一個調用中打印由較早修改的字符串。
如果轉換規(guī)范無效,則行為未定義。
... - arguments specifying data to print
1,2)如果發(fā)生錯誤,則成功寫入寬字符數或寫入負值。
3)如果編碼錯誤發(fā)生或者如果要生成的字符數等于或大于size
(包括當size
為零時),則寫入的寬字符的數目(不包括終止空寬字符)如果成功或負值。
4,5)如果發(fā)生錯誤,則成功寫入寬字符數或寫入負值。
6)寫入的寬字符數(不包括終止空值)buffer
。返回編碼錯誤和溢出時的負值。對所有其他錯誤返回零。
7)的,將已經寫入寬字符(不包括終止空)數量buffer
已經bufsz
如果發(fā)生錯誤,已經足夠大時,或為負值。(也就是說,只有當回報是非負的且小于時,寫才能成功并且完成bufsz
)
雖然窄字符串提供snprintf
了可以確定所需的輸出緩沖區(qū)大小的可能性,但對于寬字符串沒有等效(直到C11的snwprintf_s),并且為了確定緩沖區(qū)大小,程序可能需要調用swprintf
,檢查結果值,并重新分配一個更大的緩沖區(qū),再次嘗試直到成功。
snwprintf_s
不同swprintf_s
,將截斷結果以適應指向的數組buffer
,即使截斷被大多數邊界檢查函數視為錯誤。
#include <locale.h>#include <wchar.h> int main(void){ char narrow_str[] = "z\u00df\u6c34\U0001f34c"; // or "z?水?" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9f\x8d\x8c"; wchar_t warr[29]; // the expected string is 28 characters plus 1 null terminator setlocale(LC_ALL, "en_US.utf8"); swprintf(warr, sizeof warr/sizeof *warr, L"Converted from UTF-8: '%s'", narrow_str); wprintf(L"%ls\n", warr);}
輸出:
Converted from UTF-8: 'z?水?'
C11標準(ISO / IEC 9899:2011):
7.29.2.1 fwprintf函數(p:403-410)
7.29.2.3 swprintf函數(p:416)
7.29.2.11 wprintf函數(p:421)
K.3.9.1.1 fwprintf_s函數(p:628)
K.3.9.1.4 swprintf_s函數(p:630-631)
K.3.9.1.13 wprintf_s函數(p:637-638)
C99標準(ISO / IEC 9899:1999):
7.24.2.1 fwprintf函數(p:349-356)
7.24.2.3 swprintf函數(p:362)
7.24.2.11 wprintf函數(p:366)