Skip to content

satukoskinen/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_printf

Restricted implementation of the printf function from the standard C library.

The prototype is int ft_printf(char *format, ...) where format is the format string that specifies how subsequent optional arguments are converted for output.

The format string is composed of zero or more directives: either ordinary characters that are simply copied to output or conversion specifications that start with an % and consist of the following:

%[flags][minimum field width][.precision][length modifier][conversion type]

Flags, minimum field width, precision and length modifier are optional. At its simplest, the conversion specification is of the form %[conversion type], e.g. %d. %% produces the % character.

Conversion type Length modifier Precision Min. field width Flags
d, i : signed
decimal
default: int
h: short
hh: signed char
l: long
ll: long long
minimum number of digits; if only . is given, precision is taken as zero; if fewer digits are needed, the value is padded on the left with zeroes if the converted value, with
flags considered, has fewer
characters than the field width
(given as a decimal digit string),
it will be padded with spaces on the left (or right, if the - flag has been given) to fill out the given field width.
+ add a plus sign in front of a non-negative number
' ' add a blank in front of a non-negative number; ignored if + is given
0 zero padding: padding on the left with '0's instead of blanks; ignored if precision or - is given
- negative field width: values left-adjusted
o : unsigned
octal
default: unsigned int
h: unsigned short
hh: unsigned char
l: unsigned long
ll: unsigned long long
-"- -"- # precision is increased (if needed) to force the first digit to be 0
0 zero padding; ignored if precision or - is given
- negative field width
u : unsigned
decimal
-"- -"- -"- 0 zero padding; ignored if precision or - is given
- negative field width
x, X : unsigned
hexadecimal
-"- -"- -"- # non-zero result gets prefix "0x" or "0X"
0 zero padding; ignored if precision or - is given
- negative field width
c : char (int
converted to
unsigned char)
default: int - -"- - negative field width
s : character
string (pointer
to char array)
default: char* maximum number of characters to print; if precision is specified and is less than the length of the array, the string does not have to be nul-terminated -"- - negative field width
f, F : double default: double
l: double
L: long double
number of digits to appear after the decimal point; if precision is zero as in %.f or %.0f, only the integral part of the double will be printed; if precision is omitted, it is set to a default value of 6 -"- # result contains a decimal point even if precision is set to zero
+ add a plus sign in front of a non-negative number
' ' add a blank in front of a non-negative number; ignored if + is given
0 zero padding; ignored if - is given
- negative field width

About

the C printf function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published