C Programming, Coding
- June 29, 2008
Format Specifiers in C
The following format specifiers can be used when programming in C.
%d (or %i) int
%c char
%f float
%lf double
%s string
%x hexadecimal
By specifying an integer between the % and the format specifier, the number of spaces displayed can be controlled easily.
%9d will display 9 spaces before a character is displayed
%09 will display 9 zeros (0) before a character is displayed
%-9d a negative sign will left align the result
%-09d a zero(0) format will be ignored when a negative sign is used
%1.1f an integer after the period (.) specifies the number of decimal places
Other specifiers that may be needed to control the output
\n new line
\t tab
\b backspace



Sorry, comments for this entry are closed at this time.