目录搜索
AlgorithmsAlgorithms(算法)bsearchbsearch_sqsortqsort_sAtomic operationsAtomic operations library(原子操作库)ATOMIC_*_LOCK_FREEatomic_compare_exchange_strongatomic_compare_exchange_strong_explicitatomic_compare_exchange_weakatomic_compare_exchange_weak_explicitatomic_exchangeatomic_exchange_explicitatomic_fetch_addatomic_fetch_add_explicitatomic_fetch_andatomic_fetch_and_explicitatomic_fetch_oratomic_fetch_or_explicitatomic_fetch_subatomic_fetch_sub_explicitatomic_fetch_xoratomic_fetch_xor_explicitatomic_flagatomic_flag_clearatomic_flag_clear_explicitATOMIC_FLAG_INITatomic_flag_test_and_setatomic_flag_test_and_set_explicitatomic_initatomic_is_lock_freeatomic_loadatomic_load_explicitatomic_signal_fenceatomic_storeatomic_store_explicitatomic_thread_fence(线程围栏)ATOMIC_VAR_INITkill_dependencymemory_order(内存排序)C keywordsauto(自动存储)break(跳出循环)C keywords(关键词)casecharconst(常量修饰符)continuedefault(预设运算式)dodouble(双精度浮点型)elseenum(枚举类型)extern(全局变量)float(浮点数)forfortrangoto(goto语句)if(if语句)inline(行内函式)intlong(长整型)register(寄存器变量)restrict( restrict类型限定符)returnshortsignedsizeof(sizeof运算符)static(静态变量)struct(结构体)switch(switch语句)typedef(typedef关键字)union(联合体)unsigned(无符号)void(空类型)volatile(volatile变量)while(while语句)_Alignas_Alignof_Atomic_Bool_Complex_Generic_Imaginary_Noreturn_Static_assert_Thread_localC language#define directive#elif directive#else directive#endif directive#error directive#if directive#ifdef directive#ifndef directive#include directive#line directive#pragma directivealignas(对齐指定符)Alternative operators and tokens(替代运算符和令牌)AnalyzabilityArithmetic operatorsArithmetic typesArray declaration(数组声明)Array initialization(阵列初始化)ASCII ChartAssignment operators(赋值运算符)types(atomic类型限定符)Basic conceptsBit fields(位域)break statementC languageC Operator Precedencecast operatorcharacter constant(字符字面量)Comments(注释符)Comparison operators(比较运算符)compound literals(符合字面量)Conditional inclusion(条件包含)Conformance(一致性)const type qualifier(const 限定符)Constant expressions(常量表达)continue statementDeclarations(声明)do-while loopEnumerations(枚举类型)Escape sequences(转义字符)Expressions(表达式)External and tentative definitions(外部和暂定的定义)File scope(文件范围)floating constant(浮点常量)for loopFunction declarations(函数声明)Function definitions(函数声明)FunctionsGeneric selection泛型选择goto statementIdentifier(标示符)if statementImplicit conversions(隐式转换)Increment/decrement operators(前置/后置操作符)Initialization(初始化)inline function specifier(内联函式)integer constantLifetime(生命期)Logical operators(逻辑运算符)Lookup and name spacesMain function(主函式)Member access operators(会员接入运营商)Memory modelObjects and alignment(字节对齐)Order of evaluation(评估顺序)Other operatorsPhases of translation(翻译阶段)Pointer declarationPreprocessor(预处理)restrict type qualifier(restrict类型限定符)return statementScalar initialization(标量类型初始化)Scope(范围)sizeof operator(sizeof运算符)Statements(陈述)static assert declaration(静态断言声明)Static storage duration(静态存储周期)Storage-class specifiers(存储类说明符)string literals(字符串字面量)Struct and union initialization(结构体与联合体初始化)Struct declaration(结构体声明)switch statementThread storage duration(线程存储时间)TypeType(类型)Typedef declaration(Typedef声明)Undefined behavior(未定义行为)Union declaration(联合体声明)Value categories(值类别)Variadic arguments(变长参数宏)volatile type qualifier(volatile 类型限定符)while loop_Alignof operator_Noreturn function specifierDate and timeasctime(asctime函数)asctime_sclockCLOCKS_PER_SECclock_tctime(ctime函数)ctime_sDate and time utilities(日期和时间库)difftime(计算两个时间的间隔)gmtimegmtime_slocaltimelocaltime_smktime(将时间结构数据转换成经过的秒数的函数)strftime(格式化输出时间函数)timetimespectimespec_gettime_ttmwcsftime(格式化时间宽字符)Dynamic memory managementaligned_allocC memory management library(内存管理库)callocfree(释放动态分配空间的函数)malloc(动态分配内存空间的函数)realloc(重新分配内存空间的函数)Error handlingabort_handler_sassert(断言)constraint_handler_terrno(错误报告)Error handling(错误处理)Error numbers(错误个数)ignore_handler_sset_constraint_handler_sstatic_assertFile input/outputclearerr(清除/复位)fclosefeofferrorfflush(清空文件缓冲区)fgetcfgetposfgetsfgetwcfgetwsFile input/outputfopenfopen_sfprintffprintf_sfputcfputsfputwcfputwsfreadfreopenfreopen_sfscanffscanf_sfseekfsetposftellfwidefwprintffwprintf_sfwritefwscanffwscanf_sgetcgetchargetsgets_sgetwcharperrorprintfprintf_sputcputcharputsputwcputwcharremoverenamerewindscanfscanf_ssetbufsetvbufsnprintfsprintfsscanfsscanf_sswprintfswprintf_sswscanfswscanf_stmpfiletmpfile_stmpnamtmpnam_sungetcungetwcvfprintfvfprintf_svfscanfvfscanf_svfwprintfvfwprintf_svfwscanfvfwscanf_svprintfvprintf_svscanfvscanf_svsnprintfvsprintfvsscanfvsscanf_svswprintfvswprintf_svswscanfvswscanf_svwprintfvwprintf_svwscanfvwscanf_swprintfwprintf_swscanfwscanf_sLocalization supportlconvLC_ALLLC_COLLATELC_CTYPELC_MONETARYLC_NUMERICLC_TIMElocaleconvLocalization supportsetlocaleNumericsabsacosacosfacoshacoshfacoshlacoslasinasinfasinhasinhfasinhlasinlatanatan2atan2fatan2latanfatanhatanhfatanhlatanlcabscabsfcabslcacoscacosfcacoshcacoshfcacoshlcacoslcargcargfcarglcasincasinfcasinhcasinhfcasinhlcasinlcatancatanfcatanhcatanhfcatanhlcatanlcbrtcbrtfcbrtlccosccosfccoshccoshfccoshlccoslceilceilfceillcexpcexpfcexplcimagcimagfcimaglclogclogfcloglCMPLXCMPLXFCMPLXLCommon mathematical functionscomplexComplex number arithmeticconjconjfconjlcopysigncopysignfcopysignlcoscosfcoshcoshfcoshlcoslcpowcpowfcpowlcprojcprojfcprojlcrealcrealfcreallcsincsinfcsinhcsinhfcsinhlcsinlcsqrtcsqrtfcsqrtlctanctanfctanhctanhfctanhlctanldivdouble_terferfcerfcferfclerfferflexpexp2exp2fexp2lexpfexplexpm1expm1fexpm1lfabsfabsffabslfdimfeclearexceptfegetenvfegetexceptflagfegetroundfeholdexceptferaiseexceptfesetenvfesetexceptflagfesetroundfetestexceptfeupdateenvFE_ALL_EXCEPTFE_DFL_ENVFE_DIVBYZEROFE_DOWNWARDFE_INEXACTFE_INVALIDFE_OVERFLOWFE_TONEARESTFE_TOWARDZEROFE_UNDERFLOWFE_UPWARDFloating-point environmentfloat_tfloorfloorffloorlfmafmaffmalfmaxfmaxffmaxlfminfminffminlfmodfmodffmodlfpclassifyFP_INFINITEFP_NANFP_NORMALFP_SUBNORMALFP_ZEROfrexpfrexpffrexplHUGE_VALHUGE_VALFHUGE_VALLhypothypotfhypotlIilogbilogbfilogblimaginaryimaxabsimaxdivINFINITYisfiniteisgreaterisgreaterequalisinfislessislessequalislessgreaterisnanisnormalisunorderedlabsldexpldexpfldexplldivlgammalgammaflgammalllabslldivllrintllrintfllrintlllroundllroundfllroundlloglog10log10flog10llog1plog1pflog1pllog2log2flog2llogblogbflogbllogflogllrintlrintflrintllroundlroundflroundlMATH_ERREXCEPTmath_errhandlingMATH_ERRNOmodfmodffmodflnanNANnanfnanlnearbyintnearbyintfnearbyintlnextafternextafterfnextafterlnexttowardnexttowardfnexttowardlNumericspowpowfpowlPseudo-random number generationrandRAND_MAXremainderremainderfremainderlremquoremquofremquolrintrintfrintlroundroundfroundlscalblnscalblnfscalblnlscalbnscalbnfscalbnlsignbitsinsinfsinhsinhfsinhlsinlsqrtsqrtfsqrtlsrandtantanftanhtanhftanhltanltgammatgammaftgammaltrunctruncftrunclType-generic math_Complex_I_Imaginary_IProgram supportabortatexitat_quick_exitexitEXIT_FAILUREEXIT_SUCCESSgetenvgetenv_sjmp_buflongjmpProgram support utilitiesquick_exitraisesetjmpSIGABRTSIGFPESIGILLSIGINTsignalSIGSEGVSIGTERMsig_atomic_tSIG_DFLSIG_ERRSIG_IGNsystem_ExitStringsatofatoiatolatollbtowcc16rtombc32rtombchar16_tchar32_tisalnumisalphaisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitmblenmbrlenmbrtoc16mbrtoc32mbrtowcmbsinitmbsrtowcsmbsrtowcs_smbstate_tmbstowcsmbstowcs_smbtowcmemchrmemcmpmemcpymemcpy_smemmovememmove_smemsetmemset_sNull-terminated byte stringsNull-terminated multibyte stringsNull-terminated wide stringsstrcatstrcat_sstrchrstrcmpstrcollstrcpystrcpy_sstrcspnstrerrorstrerrorlen_sstrerror_sStrings librarystrlenstrncatThread supportcall_oncecnd_broadcastcnd_destroycnd_initcnd_signalcnd_timedwaitcnd_waitmtx_destroymtx_initmtx_lockmtx_plainmtx_recursivemtx_timedmtx_timedlockmtx_trylockmtx_unlockonce_flagONCE_FLAG_INITthrd_busythrd_createthrd_currentthrd_detachthrd_equalthrd_errorthrd_exitthrd_jointhrd_nomemthrd_sleepthrd_successthrd_timedoutthrd_yieldThread support librarythread_localtss_createtss_deleteTSS_DTOR_ITERATIONStss_gettss_setType supportBoolean type support libraryFixed width integer typesFLT_EVAL_METHODFLT_ROUNDSmax_align_tNULLNumeric limitsoffsetofptrdiff_tsize_tType supportVariadic functionsVariadic functionsva_argva_copyva_endva_listva_start
文字

在头文件<wchar.h>中定义



int wprintf(const wchar_t * format,...);

(自C95以来)(直到C99)


int wprintf(const wchar_t * restrict format,...);

(自C99以来)


int fwprintf(FILE * stream,const wchar_t * format,...);

(自C95以来)(直到C99)


int fwprintf(FILE * restrict stream,const wchar_t * restrict format,...);

(自C99以来)


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,...);

(自C11以来)


int fwprintf_s(FILE * restrict stream,const wchar_t * restrict format,...);

(自C11以来)


int swprintf_s(wchar_t * restrict buffer,rsize_t bufsz,const wchar_t * restrict format,...);

(自C11以来)


int snwprintf_s(wchar_t * restrict s,rsize_t n,const wchar_t * restrict format,...);

(自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_swfprintf_s,和wsprintf_s仅保证可供如果__STDC_LIB_EXT1__由实现所定义,并且如果用户定义__STDC_WANT_LIB_EXT1__的整数常数1,包括之前<stdio.h>

参数

-

输出文件流写入




































































































































缓冲

-

指向要写入的宽字符字符串的指针




































































































































bufsz

-

最多可以写入bufsz-1宽字符,加上空终止符




































































































































格式

-

pointer to a null-terminated wide string specifying how to interpret the data. The format string consists of ordinary wide characters (except %), which are copied unchanged into the output stream, and conversion specifications. Each conversion specification has the following format:   introductory % character   (optional) one or more flags that modify the behavior of the conversion:    -: the result of the conversion is left-justified within the field (by default it is right-justified)   +: the sign of signed conversions is always prepended to the result of the conversion (by default the result is preceded by minus only when it is negative)   space: if the result of a signed conversion does not start with a sign character, or is empty, space is prepended to the result. It is ignored if + flag is present.   # : alternative form of the conversion is performed. See the table below for exact effects otherwise the behavior is undefined.   0 : for integer and floating point number conversions, leading zeros are used to pad the field instead of space characters. For integer numbers it is ignored if the precision is explicitly specified. For other conversions using this flag results in undefined behavior. It is ignored if - flag is present.    (optional) integer value or * that specifies minimum field width. The result is padded with space characters (by default), if required, on the left when right-justified, or on the right if left-justified. In the case when * is used, the width is specified by an additional argument of type int. If the value of the argument is negative, it results with the - flag specified and positive field width. (Note: This is the minimum width: The value is never truncated.)    (optional) . followed by integer number or *, or neither that specifies precision of the conversion. In the case when * is used, the precision is specified by an additional argument of type int. If the value of this argument is negative, it is ignored. If neither a number nor * is used, the precision is taken as zero. See the table below for exact effects of precision.   (optional) length modifier that specifies the size of the argument   conversion format specifier           The following format specifiers are available:    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    The floating point conversion functions convert infinity to inf or infinity. Which one is used is implementation defined. Not-a-number is converted to nan or nan(char_sequence). Which one is used is implementation defined. The conversions F, E, G, A output INF, INFINITY, NAN instead. Even though %c expects int argument, it is safe to pass a char because of the integer promotion that takes place when a variadic function is called. The correct conversion specifications for the fixed-width character types (int8_t, etc) are defined in the header <inttypes.h> (although PRIdMAX, PRIuMAX, etc is synonymous with %jd, %ju, etc). The memory-writing conversion specifier %n is a common target of security exploits where format strings depend on user input and is not supported by the bounds-checked printf_s family of functions. There is a sequence point after the action of each conversion specifier; this permits storing multiple %n results in the same variable or, as an edge case, printing a string modified by an earlier %n within the same call. If a conversion specification is invalid, the behavior is undefined.

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转换样式转换将被执行。对于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































































































































ñ

将此调用到目前为止写入的字符数返回给该函数。结果写入参数指向的值。规范可能不包含任何标志,字段宽度或精度。

签名字符*

短*

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




























































































































...

-

指定要打印的数据的参数




































































































































  • 介绍%人物

  • (可选)一个或多个修改转换行为的标志:

    • -:转换的结果在字段内左对齐(默认情况下它是右对齐的)

    • +:带符号转换的符号总是预设为转换结果的前缀(默认情况下结果前面为减号,仅当它为负值时)

    • 空格:如果签名转换的结果不是以符号字符开头,或者是空的,则空格会预设为结果。如果+存在标志,则忽略它。

    • #:执行转换的替代形式。请参阅下表以了解确切的效果,否则行为未定义。

    • 0:对于整数和浮点数转换,前导零用于填充字段而不是空格字符。对于整数,如果明确指定了精度,它将被忽略。对于使用此标志的其他转换会导致未定义的行为。如果-存在标志,则忽略它。

  • (可选)整数值或*指定最小字段宽度。如果需要,结果会填充空格字符(默认情况下),右侧对齐时填充空白字符,左侧填充右侧填充。在使用的情况下*,宽度由类型的附加参数指定int。如果参数的值是负数,则结果是-指定的标志和正的字段宽度。(注意:这是最小宽度:该值从不被截断。)

    • (可选).后面跟随整数或者*或者既不指定转换的精度。在使用的情况下*精度由类型的附加参数指定int。如果这个参数的值是负数,它将被忽略。如果既不使用数字也不*使用,则精度取为零。请参阅下表以了解精确度的确切影响。

    • (可选)长度修饰符,用于指定参数的大小

    • 转换格式说明符

以下格式说明符可用:

Conversion

说明符说明参数类型长度修饰符    hh(C99)。

h   (none)   l   ll (C99).

j (C99).

z (C99).

t (C99).

L %   写文字%。完整的转换规范必须是%%。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    写入字符串参数必须是一个指向字符数组初始元素的指针,该字符数组包含一个多字节字符序列,从初始移位状态开始,转换为宽字符数组,如同通过调用mbrtowc具有零初始化转换状态。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

signed size_t

ptrdiff_t

N / A      o   将无符号整数转换为八进制表示oooo。  精度指定出现的最小位数。默认的精度是1。如果转换后的值和精度都是0没有字符的转换结果。在替代实现中,如果需要,可以增加精度以写入一个前导零。在这种情况下,如果转换值和精度都是00写入单个。

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转换样式- 使用0xh.hhh p±d

对于A转换样式- 使用0Xh.hhh P±d

0如果参数不是标准化的浮点值,则第一个十六进制数字是。如果值是0,指数也是0精度指定小数点后面出现的最小位数。默认精度足以精确表示值。在替代实现中,即使没有数字跟随,小数点字符也会被写入。对于无穷大和非数字转换风格,请参阅注释。

N/A   N/A   N/A   N/A   N/A   N/A     g

G根据值和精度    将浮点数转换为十进制或十进制指数符号。对于风格转换的转换与风格或将被执行。gef

对于G风格转换的转换与风格EF将被执行。

P等于精度如果非零,6如果没有指定精度,或者1如果精度是0。然后,如果具有样式的转换E将具有以下指数X

  • 如果P> X≥-4,转换是用式fF和精度P - 1 - X

  • 否则,转换采用样式eE精度P  -  1

除非请求替代表示,否则尾随零将被删除,如果没有剩余小数部分,小数点字符也会被删除。对于无穷大和非数字转换风格,请参阅注释。

不适用/不适用/不适用/不适用/      n   返回此函数迄今为止写入的字符数。结果写入参数指向的值。规范可能不包含任何标志字段宽度精度

signed char*

short*

int*

long*

long long*

intmax_t*

signed size_t*

ptrdiff_t*

N / A      p   写入一个实现定义的字符序列来定义一个指针。不适用不适用不适用不适用不适用不适用    void*   浮点转换函数将无穷大转换为infinfinity。使用哪一个是实现定义的。

非数字转换为nan或。使用哪一个是实现定义的。nan(char_sequence)

该转换FEGA输出INFINFINITYNAN来代替。

即使%c需要int参数,通过char调用可变参数函数时发生的整数提升也是安全的。

对于固定宽度的字符类型(正确的转换规格int8_t<inttypes.h>还(虽然,等等)都在头定义PRIdMAXPRIuMAX等是同义词%jd%ju等)。

内存写入转换说明符%n是安全漏洞的常见目标,其中格式字符串取决于用户输入,并且不受边界检查printf_s函数族的支持。

每个转换说明符的操作之后都有一个序列点; 这允许将多个%n结果存储在相同的变量中,或者作为边缘情况,%n在同一个调用中打印由较早修改的字符串。

如果转换规范无效,则行为未定义。

 ...   -   arguments specifying data to print

返回值

1,2)如果发生错误,则成功写入宽字符数或写入负值。

3)如果编码错误发生或者如果要生成的字符数等于或大于size(包括当size为零时),则写入的宽字符的数目(不包括终止空宽字符)如果成功或负值。

4,5)如果发生错误,则成功写入宽字符数或写入负值。

6)写入的宽字符数(不包括终止空值)buffer。返回编码错误和溢出时的负值。对所有其他错误返回零。

7)的,将已经写入宽字符(不包括终止空)数量buffer已经bufsz如果发生错误,已经足够大时,或为负值。(也就是说,只有当回报是非负的且小于时,写才能成功并且完成bufsz

注意

虽然窄字符串提供snprintf了可以确定所需的输出缓冲区大小的可能性,但对于宽字符串没有等效(直到C11的snwprintf_s),并且为了确定缓冲区大小,程序可能需要调用swprintf,检查结果值,并重新分配一个更大的缓冲区,再次尝试直到成功。

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)

上一篇:下一篇: