<<Navigation: 执行失败 ['AllContext' object has no attribute 'values'] (see also the log)>>

B.1.2 Formatted Output

The printf functions provide formatted output conversion.

   int fprintf(FILE *stream, const char *format, ...)

fprintf converts and writes output to stream under the control of format. The return value is the number of characters written, or negative if an error occurred.

The format string contains two types of objects: ordinary characters, which are copied to the output stream, and conversion specifications, each of which causes conversion and printing of the next successive argument to fprintf. Each conversion specification begins with the character % and ends with a conversion character. Between the % and the conversion character there may be, in order:

Width or precision or both may be specified as *, in which case the value is computed by converting the next argument(s), which must be int.

The conversion characters and their meanings are shown in Table B.1. If the character after the % is not a conversion character, the behavior is undefined.

Table B.1 Printf Conversions

Character

Argument type;

Printed As

d,i

int;

signed decimal notation.

o

int;

unsigned octal notation (without a leading zero).

x,X

unsigned int;

unsigned hexadecimal notation (without a leading 0x or 0X), using abcdef for 0x or ABCDEF for 0X.

u

int;

unsigned decimal notation.

c

int;

single character, after conversion to unsigned char

s

char *;

characters from the string are printed until a '\0' is reached or until the number of characters indicated by the precision have been printed.

f

double;

decimal notation of the form [-]mmm.ddd, where the number of d's is given by the precision. The default precision is 6; a precision of 0 suppresses the decimal point.

e,E

double;

decimal notation of the form [-]m.dddddde+/-xx or [-]m.ddddddE+/-xx, where the number of d's is specified by the precision. The default precision is 6; a precision of 0 suppresses the decimal point.

g,G

double;

%e or %E is used if the exponent is less than -4 or greater than or equal to the precision; otherwise %f is used. Trailing zeros and a trailing decimal point are not printed.

p

void *;

print as a pointer (implementation-dependent representation).

n

int *;

the number of characters written so far by this call to printf is written into the argument. No argument is converted.

%

no argument is converted;

print a %

int printf(const char *format, ...)

int sprintf(char *s, const char *format, ...)

int vprintf(const char *format, va_list arg)
int vfprintf(FILE *stream, const char *format, va_list arg)
int vsprintf(char *s, const char *format, va_list arg)

TCPL/B.01.2_Formatted_Output (2008-02-23 15:35:14由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.