Benutzer-Werkzeuge

Webseiten-Werkzeuge


edv:prg:c:datatyp:printf_-_formatierungszeichen

printf() - Formatierungszeichen

Formatzeichen / Steuerzeichen / Escape-Sequenzen

Steuerzeichen Beschreibung
\a BEL (Bell)
\b BS (Backspace)
\f FF (Formfeed)
\n NL (Newline)
\r CR (Carriage Return)
\t HT (Horizontal Tab)
\v VT (Vertical Tab)
\" "-Zeichen
\' '-Zeichen
\? ?-Zeichen
\\ \-Zeichen
\0 NULL-Zeichen
\nnn Ausgabe eines Oktalwerts (z. B. \033 = ESCAPE-Zeichen)
\xhh Ausgabe eines HEX-Werts
\uXXXX
\UXXXXXXXX
Zeichen eines größeren Zeichensatzes (bspw. Unicode)

Ausgabe von Variablen

Formatierungszeichen werden nach folgendem Muster zusammengesetzt:

%[flags][width][.precision][length]specifier

Wobei specifier kann folgende "Werte" annehmen:

specifier Beschreibung
d, i int (integer mit Vorzeichen)
u unsigned int
o int als unsigned octal
x, X unsigned int in HEX-Darstellung (x - Kleinbuchstaben, X - Großbuchstaben)
f, F double - Decimal floating point (f -Kleinbuchstaben, F - Großbuchstaben)
e, E floating point - wissenschaftliche Darstellung: Mantissa/Exponent, (e - Kleinbuchstaben, E - Großbuchstaben)
g, G kürzeste Darstellung: %e oder %f bzw. %E oder %F
a, A floating point in HEX-Darstellung (a - Kleinbuchstaben, A - Großbuchstaben)
c char (einzelnes Zeichen)
s String ('\0'-terminierte Zeichenkette)
p Pointer address
n :?:
% Das '%'-Zeichen gefolgt vom nächsten '%'-Zeichen gibt ein einziges '%'-Zeichen im Ergebnis aus.

flags kann folgende "Werte" annehmen:

flags Beschreibung
- Linksbündig innerhalb der vorgegebenen Feldbreite; Rechtsbündig ist default (s. Beschreibung für "width").
+ Vorzeichen (+ oder -) wird auf jedem Fall dargestellt. Defaultmäßig werden nur die negativen Zahlen mit '-'-Zeichen dargestellt.
space:?: If no sign is going to be written, a blank space is inserted before the value.
# :?: Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero.
Used with a, A, e, E, f, F, g or G it forces the written output to contain a decimal point even if no more digits follow. By default, if no digits follow, no decimal point is written.
0 :?: Left-pads the number with zeroes (0) instead of spaces when padding is specified (see width sub-specifier).

width kann folgende "Werte" annehmen:

width Beschreibung
Ganzzahl:?: Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
* :?: The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

.precision kann folgende "Werte" annehmen:

.precision Beschreibung
.Ganzzahl :?: For integer specifiers (d, i, o, u, x, X): precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0.
For a, A, e, E, f and F specifiers: this is the number of digits to be printed after the decimal point (by default, this is 6).
For g and G specifiers: This is the maximum number of significant digits to be printed.
For s: this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered.
If the period is specified without an explicit value for precision, 0 is assumed.
.* :?: The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

length kann folgende "Werte" annehmen:

FIXME

Diese Informationen wurden folgender WebSeite entnommen:
http://www.cplusplus.com/reference/cstdio/printf/


Stand: 18.03.2016
: Jürgen Kreick

EOF

edv/prg/c/datatyp/printf_-_formatierungszeichen.txt · Zuletzt geändert: 2020/01/11 01:23 von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki