The Math Functions (MATH.H)
Visual C++ 6(c) The Complete Reference
Authors: Pappas C.H. Murray W.H.
Published year: 1998
Pages: 99/207
Buy this book on amazon.com >>

Chapter 11 - Complete I/O in C

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

Formatting Output
Cs rich assortment of output formatting controls makes it easy to create a neatly printed graph, report, or table. The two main functions that accomplish this formatted output are printf() and the file equivalent form, fprintf(). These functions can use any of the format specifiers shown in Table 11-2. The format specification uses the following form:
Table 11-2: Format Specifiers for printf() and fprintf() Functions
TYPE FIELD:
Character

Type

Format of Output
c
int or wint_t
printf() means a
single-byte character.
wprintf() means a
wide character.
C
int or wint_t
printf() means a
wide character.
wprintf() means a single-byte character.
d
int
Signed decimal integer.
e
double
Signed number of the form [ - ]d.ddd e [sign]dddd.
Here, d is a single decimal digit, ddd is one or more decimal digits, dddd is exactly four decimal digits, and the sign is a + or - .
E
double
Same as e, except E is in front of exponent.
f
double
Signed number of the form [ - ]ddd.ddd. Here, ddd is one or more decimal digits. The number of digits after the decimal point depends upon the precision.
g
double
Signed number in f or e format. The most compact format is used. No trailing zeroes. No decimal point if no digits follow it.
G
double
Same as g format, except E is in front of exponent.
i
int
Signed decimal integer.
n
Pointer to integer
The # of characters written
to the stream or buffer.
Address of buffer given as integer argument.
o
int
Unsigned octal integer.
p
Pointer to void
Address (given by argument) is printed.
s
String
printf() gives a single-byte-character string.
wprintf() gives a wide-character string.
(print to NULL or
max precision)
S
String
printf() gives a wide-character string.
wprintf() gives a single-byte-character string.
(print to NULL or max precision)
u
int
Unsigned decimal integer.
x
int
Unsigned hexadecimal integer (lowercase letters used).
X
int
Unsigned hexadecimal integer (uppercase
letters used).
FLAG FIELD:
Flag

Meaning
-
Left-align the result (right alignment is the default).
+
Use a leading sign (+ or - ) if number is a signed type (sign used with negative number only is the default).
When width has 0 prefix, zeroes will be added until the minimum width is reached (no padding is the default).
blank (
Visual C++ 6(c) The Complete Reference
Authors: Pappas C.H. Murray W.H.
Published year: 1998
Pages: 99/207