目录 搜索
Algorithms Algorithms(算法) bsearch bsearch_s qsort qsort_s Atomic operations Atomic operations library(原子操作库) ATOMIC_*_LOCK_FREE atomic_compare_exchange_strong atomic_compare_exchange_strong_explicit atomic_compare_exchange_weak atomic_compare_exchange_weak_explicit atomic_exchange atomic_exchange_explicit atomic_fetch_add atomic_fetch_add_explicit atomic_fetch_and atomic_fetch_and_explicit atomic_fetch_or atomic_fetch_or_explicit atomic_fetch_sub atomic_fetch_sub_explicit atomic_fetch_xor atomic_fetch_xor_explicit atomic_flag atomic_flag_clear atomic_flag_clear_explicit ATOMIC_FLAG_INIT atomic_flag_test_and_set atomic_flag_test_and_set_explicit atomic_init atomic_is_lock_free atomic_load atomic_load_explicit atomic_signal_fence atomic_store atomic_store_explicit atomic_thread_fence(线程围栏) ATOMIC_VAR_INIT kill_dependency memory_order(内存排序) C keywords auto(自动存储) break(跳出循环) C keywords(关键词) case char const(常量修饰符) continue default(预设运算式) do double(双精度浮点型) else enum(枚举类型) extern(全局变量) float(浮点数) for fortran goto(goto语句) if(if语句) inline(行内函式) int long(长整型) register(寄存器变量) restrict( restrict类型限定符) return short signed sizeof(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_local C language #define directive #elif directive #else directive #endif directive #error directive #if directive #ifdef directive #ifndef directive #include directive #line directive #pragma directive alignas(对齐指定符) Alternative operators and tokens(替代运算符和令牌) Analyzability Arithmetic operators Arithmetic types Array declaration(数组声明) Array initialization(阵列初始化) ASCII Chart Assignment operators(赋值运算符) types(atomic类型限定符) Basic concepts Bit fields(位域) break statement C language C Operator Precedence cast operator character constant(字符字面量) Comments(注释符) Comparison operators(比较运算符) compound literals(符合字面量) Conditional inclusion(条件包含) Conformance(一致性) const type qualifier(const 限定符) Constant expressions(常量表达) continue statement Declarations(声明) do-while loop Enumerations(枚举类型) Escape sequences(转义字符) Expressions(表达式) External and tentative definitions(外部和暂定的定义) File scope(文件范围) floating constant(浮点常量) for loop Function declarations(函数声明) Function definitions(函数声明) Functions Generic selection泛型选择 goto statement Identifier(标示符) if statement Implicit conversions(隐式转换) Increment/decrement operators(前置/后置操作符) Initialization(初始化) inline function specifier(内联函式) integer constant Lifetime(生命期) Logical operators(逻辑运算符) Lookup and name spaces Main function(主函式) Member access operators(会员接入运营商) Memory model Objects and alignment(字节对齐) Order of evaluation(评估顺序) Other operators Phases of translation(翻译阶段) Pointer declaration Preprocessor(预处理) restrict type qualifier(restrict类型限定符) return statement Scalar initialization(标量类型初始化) Scope(范围) sizeof operator(sizeof运算符) Statements(陈述) static assert declaration(静态断言声明) Static storage duration(静态存储周期) Storage-class specifiers(存储类说明符) string literals(字符串字面量) Struct and union initialization(结构体与联合体初始化) Struct declaration(结构体声明) switch statement Thread storage duration(线程存储时间) Type Type(类型) Typedef declaration(Typedef声明) Undefined behavior(未定义行为) Union declaration(联合体声明) Value categories(值类别) Variadic arguments(变长参数宏) volatile type qualifier(volatile 类型限定符) while loop _Alignof operator _Noreturn function specifier Date and time asctime(asctime函数) asctime_s clock CLOCKS_PER_SEC clock_t ctime(ctime函数) ctime_s Date and time utilities(日期和时间库) difftime(计算两个时间的间隔) gmtime gmtime_s localtime localtime_s mktime(将时间结构数据转换成经过的秒数的函数) strftime(格式化输出时间函数) time timespec timespec_get time_t tm wcsftime(格式化时间宽字符) Dynamic memory management aligned_alloc C memory management library(内存管理库) calloc free(释放动态分配空间的函数) malloc(动态分配内存空间的函数) realloc(重新分配内存空间的函数) Error handling abort_handler_s assert(断言) constraint_handler_t errno(错误报告) Error handling(错误处理) Error numbers(错误个数) ignore_handler_s set_constraint_handler_s static_assert File input/output clearerr(清除/复位) fclose feof ferror fflush(清空文件缓冲区) fgetc fgetpos fgets fgetwc fgetws File input/output fopen fopen_s fprintf fprintf_s fputc fputs fputwc fputws fread freopen freopen_s fscanf fscanf_s fseek fsetpos ftell fwide fwprintf fwprintf_s fwrite fwscanf fwscanf_s getc getchar gets gets_s getwchar perror printf printf_s putc putchar puts putwc putwchar remove rename rewind scanf scanf_s setbuf setvbuf snprintf sprintf sscanf sscanf_s swprintf swprintf_s swscanf swscanf_s tmpfile tmpfile_s tmpnam tmpnam_s ungetc ungetwc vfprintf vfprintf_s vfscanf vfscanf_s vfwprintf vfwprintf_s vfwscanf vfwscanf_s vprintf vprintf_s vscanf vscanf_s vsnprintf vsprintf vsscanf vsscanf_s vswprintf vswprintf_s vswscanf vswscanf_s vwprintf vwprintf_s vwscanf vwscanf_s wprintf wprintf_s wscanf wscanf_s Localization support lconv LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME localeconv Localization support setlocale Numerics abs acos acosf acosh acoshf acoshl acosl asin asinf asinh asinhf asinhl asinl atan atan2 atan2f atan2l atanf atanh atanhf atanhl atanl cabs cabsf cabsl cacos cacosf cacosh cacoshf cacoshl cacosl carg cargf cargl casin casinf casinh casinhf casinhl casinl catan catanf catanh catanhf catanhl catanl cbrt cbrtf cbrtl ccos ccosf ccosh ccoshf ccoshl ccosl ceil ceilf ceill cexp cexpf cexpl cimag cimagf cimagl clog clogf clogl CMPLX CMPLXF CMPLXL Common mathematical functions complex Complex number arithmetic conj conjf conjl copysign copysignf copysignl cos cosf cosh coshf coshl cosl cpow cpowf cpowl cproj cprojf cprojl creal crealf creall csin csinf csinh csinhf csinhl csinl csqrt csqrtf csqrtl ctan ctanf ctanh ctanhf ctanhl ctanl div double_t erf erfc erfcf erfcl erff erfl exp exp2 exp2f exp2l expf expl expm1 expm1f expm1l fabs fabsf fabsl fdim feclearexcept fegetenv fegetexceptflag fegetround feholdexcept feraiseexcept fesetenv fesetexceptflag fesetround fetestexcept feupdateenv FE_ALL_EXCEPT FE_DFL_ENV FE_DIVBYZERO FE_DOWNWARD FE_INEXACT FE_INVALID FE_OVERFLOW FE_TONEAREST FE_TOWARDZERO FE_UNDERFLOW FE_UPWARD Floating-point environment float_t floor floorf floorl fma fmaf fmal fmax fmaxf fmaxl fmin fminf fminl fmod fmodf fmodl fpclassify FP_INFINITE FP_NAN FP_NORMAL FP_SUBNORMAL FP_ZERO frexp frexpf frexpl HUGE_VAL HUGE_VALF HUGE_VALL hypot hypotf hypotl I ilogb ilogbf ilogbl imaginary imaxabs imaxdiv INFINITY isfinite isgreater isgreaterequal isinf isless islessequal islessgreater isnan isnormal isunordered labs ldexp ldexpf ldexpl ldiv lgamma lgammaf lgammal llabs lldiv llrint llrintf llrintl llround llroundf llroundl log log10 log10f log10l log1p log1pf log1pl log2 log2f log2l logb logbf logbl logf logl lrint lrintf lrintl lround lroundf lroundl MATH_ERREXCEPT math_errhandling MATH_ERRNO modf modff modfl nan NAN nanf nanl nearbyint nearbyintf nearbyintl nextafter nextafterf nextafterl nexttoward nexttowardf nexttowardl Numerics pow powf powl Pseudo-random number generation rand RAND_MAX remainder remainderf remainderl remquo remquof remquol rint rintf rintl round roundf roundl scalbln scalblnf scalblnl scalbn scalbnf scalbnl signbit sin sinf sinh sinhf sinhl sinl sqrt sqrtf sqrtl srand tan tanf tanh tanhf tanhl tanl tgamma tgammaf tgammal trunc truncf truncl Type-generic math _Complex_I _Imaginary_I Program support abort atexit at_quick_exit exit EXIT_FAILURE EXIT_SUCCESS getenv getenv_s jmp_buf longjmp Program support utilities quick_exit raise setjmp SIGABRT SIGFPE SIGILL SIGINT signal SIGSEGV SIGTERM sig_atomic_t SIG_DFL SIG_ERR SIG_IGN system _Exit Strings atof atoi atol atoll btowc c16rtomb c32rtomb char16_t char32_t isalnum isalpha isblank iscntrl isdigit isgraph islower isprint ispunct isspace isupper iswalnum iswalpha iswblank iswcntrl iswctype iswdigit iswgraph iswlower iswprint iswpunct iswspace iswupper iswxdigit isxdigit mblen mbrlen mbrtoc16 mbrtoc32 mbrtowc mbsinit mbsrtowcs mbsrtowcs_s mbstate_t mbstowcs mbstowcs_s mbtowc memchr memcmp memcpy memcpy_s memmove memmove_s memset memset_s Null-terminated byte strings Null-terminated multibyte strings Null-terminated wide strings strcat strcat_s strchr strcmp strcoll strcpy strcpy_s strcspn strerror strerrorlen_s strerror_s Strings library strlen strncat Thread support call_once cnd_broadcast cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait mtx_destroy mtx_init mtx_lock mtx_plain mtx_recursive mtx_timed mtx_timedlock mtx_trylock mtx_unlock once_flag ONCE_FLAG_INIT thrd_busy thrd_create thrd_current thrd_detach thrd_equal thrd_error thrd_exit thrd_join thrd_nomem thrd_sleep thrd_success thrd_timedout thrd_yield Thread support library thread_local tss_create tss_delete TSS_DTOR_ITERATIONS tss_get tss_set Type support Boolean type support library Fixed width integer types FLT_EVAL_METHOD FLT_ROUNDS max_align_t NULL Numeric limits offsetof ptrdiff_t size_t Type support Variadic functions Variadic functions va_arg va_copy va_end va_list va_start
文字

Defined in header <stdio.h>




(1)


int vprintf( const char *format, va_list vlist );

(until C99)


int vprintf( const char *restrict format, va_list vlist );

(since C99)



(2)


int vfprintf( FILE *stream, const char *format, va_list vlist );

(until C99)


int vfprintf( FILE *restrict stream, const char *restrict format,                va_list vlist );

(since C99)



(3)


int vsprintf( char *buffer, const char *format, va_list vlist );

(until C99)


int vsprintf( char *restrict buffer, const char *restrict format,                va_list vlist );

(since C99)


int vsnprintf( char *restrict buffer, int bufsz,                 const char *restrict format, va_list vlist );

(4)

(since C99)

int vprintf_s( const char *restrict format, va_list arg);

(5)

(since C11)

int vfprintf_s( FILE *restrict stream, const char *restrict format,                 va_list arg);

(6)

(since C11)

int vsprintf_s( char *restrict buffer, rsize_t bufsz,                 const char *restrict format, va_list arg);

(7)

(since C11)

int vsnprintf_s(char *restrict buffer, rsize_t bufsz,                 const char * restrict format, va_list arg);

(8)

(since C11)

从定义的位置加载数据vlist,将它们转换为等同字符串并将结果写入各种接收器。

1)将结果写入stdout

2)将结果写入文件流stream

3)将结果写入字符串buffer

4)将结果写入字符串buffer。最多的buf_size字符是写入的。结果字符串将以空字符结尾,除非buf_size为零。如果buf_size为零,则不会写入任何内容,并且buffer可能是空指针,但返回值(将写入的字节数)仍然会计算并返回。

5-8)与(1-4)相同,只是在运行时检测到以下错误并调用当前安装的约束处理函数:

  • 转换说明符%n存在于format

  • 任何对应的参数%s都是空指针

  • format或者buffer是空指针

  • bufsz 是零或大于 RSIZE_MAX

  • 编码错误出现在任何字符串和字符转换说明符中

  • vsprintf_s仅限于),要存储的字符串buffer(包括结尾空值))将被超出bufsz

由于所有的边界检查功能,vprintf_svfprintf_svsprintf_s,和vsnrintf_s仅保证可供如果__STDC_LIB_EXT1__由实现所定义,并且如果用户定义__STDC_WANT_LIB_EXT1__的整数常数1,包括之前<stdio.h>

参数

-

输出文件流写入




































































































































缓冲

-

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




































































































































bufsz

-

最多bufsz  - 可能会写入1个字符,再加上空终止符




































































































































格式

-

指向以空字符结尾的字符串的指针,指定如何解释数据。格式字符串由普通的多字节字符(%除外)组成,它们被原样复制到输出流和转换规范中。每个转换规范具有以下格式:介绍%字符(可选)一个或多个标志,用于修改转换的行为: - :转换结果在字段内左对齐(默认情况下,它是右对齐的)+ :带符号转换的符号总是作为转换结果的前缀(默认情况下,只有当结果为负时,结果才以负值开头)space:如果带符号转换的结果不是以符号字符开头,或者是空的,空间是预先考虑的结果。如果存在+标志,则忽略它。#:执行转换的替代形式。请参阅下表以了解确切的效果,否则行为未定义。0:对于整数和浮点数转换,前导零用于填充字段而不是空格字符。对于整数,如果明确指定了精度,它将被忽略。对于使用此标志的其他转换会导致未定义的行为。如果 - 标志存在,它将被忽略。(可选)整数值或*指定最小字段宽度。如果需要,结果会填充空格字符(默认情况下),右侧对齐时填充空白字符,左侧填充右侧填充。在使用*的情况下,宽度由类型为int的附加参数指定。如果参数的值是负值,那么结果是指定 - 标志和正字段宽度。(注意:这是最小宽度:该值从不被截断。)(可选)。后跟整数或*,或者两者都不指定转换的精度。在使用*的情况下,精度由类型为int的附加参数指定。如果这个参数的值是负数,它将被忽略。如果既不使用数字也不使用*,则精度取为零。请参阅下表以了解精确度的确切影响。(可选)长度修饰符,用于指定参数转换格式说明符的大小以下格式说明符可用:转换说明符说明参数类型长度修饰符hh(C99)。h(无)ll(C99)。j(C99)。z(C99)。t(C99)。L%写文字%。完整的转换规范必须是%%。不适用不适用不适用不适用不适用不适用不适用不适用不适用单个字符。该参数首先转换为无符号字符。如果使用l修饰符,则首先将参数转换为字符串,就好像通过具有wchar_t2参数的%ls一样。N / AN / A int wint_t N / AN / AN / AN / AN / A s写入字符串参数必须是指向字符数组的初始元素的指针。Precision指定要写入的最大字节数。如果未指定Precision,则将每个字节写入并不包括第一个空终止符。如果使用l说明符,则参数必须是指向wchar_t数组的初始元素的指针,该数组转换为char数组,就好像通过调用具有零初始化转换状态的wcrtomb一样。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转换样式转换将被执行。对于G转换样式,将使用样式E或F进行转换。假设P等于非零的精度,如果未指定精度,则等于6;如果精度为0,则等于1。然后,如果具有样式E的转换将具有X的指数:如果P> X≥-4,则转换具有样式f或F和精度P-1-X。否则,转换具有样式e或E以及精度P  -  1.除非要求替代表示,否则尾随零将被删除,如果没有剩余小数部分,小数点字符也会被删除。对于无限和非数字转换风格,请参阅注释。不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用不适用 结果写入参数指向的值。规范可能不包含任何标志,字段宽度或精度。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参数,但因为在调用可变参数函数时发生整数提升,所以传递char是安全的。固定宽度字符类型(int8_t等)的正确转换规范在标头<inttypes.h>中定义(尽管PRIdMAX,PRIuMAX等与%jd,%ju等同义)。内存写入转换说明符%n是格式字符串依赖用户输入并且不受边界检查的printf_s系列函数支持的安全漏洞的常见目标。每个转换说明符的操作之后都有一个序列点; 这允许在同一个变量中存储多个%n个结果,或者,作为边界案例,在同一个调用中打印由较早的%n修改的字符串。如果转换规范无效,则行为未定义。由于在调用可变参数函数时发生整数提升,所以传递char是安全的。固定宽度字符类型(int8_t等)的正确转换规范在标头<inttypes.h>中定义(尽管PRIdMAX,PRIuMAX等与%jd,%ju等同义)。内存写入转换说明符%n是格式字符串依赖用户输入并且不受边界检查的printf_s系列函数支持的安全漏洞的常见目标。每个转换说明符的操作之后都有一个序列点; 这允许在同一个变量中存储多个%n个结果,或者,作为边界案例,在同一个调用中打印由较早的%n修改的字符串。如果转换规范无效,则行为未定义。由于在调用可变参数函数时发生整数提升,所以传递char是安全的。固定宽度字符类型(int8_t等)的正确转换规范在标头<inttypes.h>中定义(尽管PRIdMAX,PRIuMAX等与%jd,%ju等同义)。内存写入转换说明符%n是格式字符串依赖用户输入并且不受边界检查的printf_s系列函数支持的安全漏洞的常见目标。每个转换说明符的操作之后都有一个序列点; 这允许在同一个变量中存储多个%n个结果,或者,作为边界案例,在同一个调用中打印由较早的%n修改的字符串。如果转换规范无效,则行为未定义。

转换说明符

说明

参数类型

长度修饰符

hh(C99)。

H

(没有)

(C99)。

j(C99)。

来自(C99)。

t(C99)。

%

写文字%。完整的转换规范必须是%%。

N / A

N / A

N / A

N / A

N / A

N / A

N / A

N / A

N / A

C

写一个字符。该参数首先转换为无符号字符。如果使用l修饰符,则首先将参数转换为字符串,就好像通过具有wchar_t2参数的%ls一样。

N / A

N / A

INT

所述wint_t

N / A

N / A

N / A

N / A

N / A

小号

writes a character string  The argument must be a pointer to the initial element of an array of characters. Precision specifies the maximum number of bytes to be written. If Precision is not specified, writes every byte 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, which is converted to char array as if by a call to wcrtomb with zero-initialized conversion state.

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

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

签名字符*

短*

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

转换说明符

说明

参数类型




































































































































长度修饰符

hh(C99)。

H

(没有)

(C99)。

j(C99)。

来自(C99)。

t(C99)。





























































































































%

写文字%。完整的转换规范必须是%%。

N / A

N / A

N / A

N / A

N / A

N / A

N / A

N / A

N / A




























































































































C

写一个字符。该参数首先转换为无符号字符。如果使用l修饰符,则首先将参数转换为字符串,就好像通过具有wchar_t2参数的%ls一样。

N / A

N / A

INT

所述wint_t

N / A

N / A

N / A

N / A

N / A




























































































































小号

写入字符串参数必须是指向字符数组的初始元素的指针。Precision指定要写入的最大字节数。如果未指定Precision,则将每个字节写入并不包括第一个空终止符。如果使用l说明符,则参数必须是指向wchar_t数组的初始元素的指针,该数组转换为char数组,就好像通过调用具有零初始化转换状态的wcrtomb一样。

N / A

N / A

字符*

wchar_t的*

N / A

N / A

N / A

N / A

N / A




























































































































将有符号的整数转换为十进制表示形式-dddd。精度指定出现的最小位数。默认精度为1.如果转换值和精度均为0,则转换不会生成任何字符。

签名字符

INT

long

漫长的

还会将intmax_t

签名size_t

ptrdiff_t的

N / A




























































































































将无符号整数转换为八进制表示oooo。精度指定出现的最小位数。默认精度为1.如果转换值和精度均为0,则转换不会生成任何字符。在替代实现中,如果需要,可以增加精度以写入一个前导零。在这种情况下,如果转换值和精度均为0,则写入单个0。

无符号字符

无符号短

无符号整数

无符号长整数

无符号long long

uintmax_t型

为size_t

未签名的ptrdiff_t版本

N / A




























































































































x X

将无符号整数转换为十六进制表示hhhh。对于x转换字母abcdef被使用。对于X转换字母使用ABCDEF。精度指定出现的最小位数。默认精度为1.如果转换值和精度均为0,则转换不会生成任何字符。在替代实现中,如果转换后的值为非零值,则0x或0X将作为结果的前缀。

N / A




































































































































将无符号整数转换为十进制表示形式dddd。精度指定出现的最小位数。默认精度为1.如果转换值和精度均为0,则转换不会生成任何字符。

N / A




































































































































f

将浮点数转换为样式-ddd.ddd中的小数表示法。精度指定小数点后面出现的最小位数。默认精度为6.在替代实现中,即使没有数字跟随,小数点字符也会被写入。对于无穷大和非数字转换风格,请参阅注释。

N / A

N / A

双(C99)

N / A

N / A

N / A

N / A

长双




























































































































和E

将浮点数转换为十进制指数符号。对于e转换样式,使用-d.ddde±dd。对于E转换样式,使用-d.dddE±dd。指数至少包含两位数字,只有在必要时才使用更多数字。如果该值为0,则指数也为0。精度指定小数点后面出现的最小位数。默认精度为6.在替代实现中,即使没有数字跟随,小数点字符也会被写入。对于无穷大和非数字转换风格,请参阅注释。

N / A

N / A

N / A

N / A

N / A

N / 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




























































































































VLIST

-

包含要打印的数据的变量参数列表




































































































































  • 介绍%字符

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

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

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

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

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

    • 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    写入单个字符。该论点首先转换为unsigned char。如果使用了l修饰符,则首先将参数转换为字符串,就像通过具有参数的%ls一样wchar_t[2]

N/A   N/A   int

wint_t

N / AN / AN / AN / AN / A      s    写入字符串参数必须是指向字符数组的初始元素的指针。Precision指定要写入的最大字节数。如果未指定Precision,则将每个字节写入并不包括第一个空终止符。如果使用了l说明符,则参数必须是指向数组初始元素的指针wchar_t,它将转换为char数组,就像通过调用wcrtomb具有零初始化转换状态一样。

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在同一个调用中打印由较早修改的字符串。

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

 vlist   -   variable argument list containing the data to print

返回值

1-3)如果发生错误,则写入的字符数如果成功或为负值。

4)如果发生错误,则成功写入字符数或写入负值。如果由于buf_size限制而导致结果字符串被截断,则函数将返回如果未施加该限制的情况下将被写入的字符总数(不包括终止空字节)。

5,6)传输到输出流的字符数或负值(如果发生输出错误,运行时间约束违规错误或编码错误)。

7)写入的字符数buffer,不包括空字符(只要buffer不是空指针,bufsz并且不为零且不大于RSIZE_MAX),则不计入空字符,或者在运行时约束违规时为零,编码错误为负值

8)不包括终止空字符的字符数(只要buffer不是空指针并且bufsz不为零且不大于RSIZE_MAX),buffer如果bufsz被忽略,将被写入的字符数或者如果运行时约束违规或编码错误发生

笔记

所有这些函数va_arg至少调用一次,arg返回后的值是不确定的。这些函数不会调用va_end,并且它必须由调用者完成。

vsnprintf_s不像vsprintf_s,会截断结果以适应指向的数组buffer

#include <stdio.h>#include <stdarg.h>#include <time.h> void debug_log(const char *fmt, ...){
    struct timespec ts;    timespec_get(&ts, TIME_UTC);
    char time_buf[100];
    size_t rc = strftime(time_buf, sizeof time_buf, "%D %T", gmtime(&ts.tv_sec));    snprintf(time_buf + rc, sizeof time_buf - rc, ".%06ld UTC", ts.tv_nsec / 1000);
 
    va_list args1;    va_start(args1, fmt);
    va_list args2;    va_copy(args2, args1);
    char buf[1+vsnprintf(NULL, 0, fmt, args1)];    va_end(args1);    vsnprintf(buf, sizeof buf, fmt, args2);    va_end(args2); 
    printf("%s [debug]: %s\n", time_buf, buf);}
 int main(void){    debug_log("Logging, %d, %d, %d", 1, 2, 3);}

可能的输出:

02/20/15 21:58:09.072683 UTC [debug]: Logging, 1, 2, 3

参考

  • C11 standard (ISO/IEC 9899:2011):

    • 7.21.6.8 The vfprintf function (p: 326-327)

    • 7.21.6.10 The vprintf function (p: 328)

    • 7.21.6.12 The vsnprintf function (p: 329)

    • 7.21.6.13 The vsprintf function (p: 329)

    • K.3.5.3.8 The vfprintf_s function (p: 597)

    • K.3.5.3.10 The vprintf_s function (p: 598-599)

    • K.3.5.3.12 The vsnprintf_s function (p: 600)

    • K.3.5.3.13 The vsprintf_s function (p: 601)

  • C99 standard (ISO/IEC 9899:1999):

    • 7.19.6.8 The vfprintf function (p: 292)

    • 7.19.6.10 The vprintf function (p: 293)

    • 7.19.6.12 The vsnprintf function (p: 294)

    • 7.19.6.13 The vsprintf function (p: 295)

  • C89/C90 standard (ISO/IEC 9899:1990):

    • 4.9.6.7 The vfprintf function

    • 4.9.6.8 The vprintf function

    • 4.9.6.9 The vsprintf function

上一篇: 下一篇: