Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

#####Implementation of C function : printf

intmy_printf(char*format, ...);

###To use it:

make And you will get two libraries. Compile with one of them to use my_printf function. Example with the file test.c given in test folder gcc test/test.c libmy_printf_'uname -m'-'uname -s'.a or gcc test/test.c libmy_printf_'uname -m'-'uname -s'.souname -m and uname -s depends on your system

####Syntax to format:

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

####Flags:

FlagDescription
+Sign displayed even if positive number is passed.
#Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero.

####Width:

If defined, width allows you to print only n characters where n is equal to what you have assigned to width

#####Example:

my_printf("%10d\n", 42);

will result to

42

####Precision:

If defined, precision allows you to print only n characters of your variable where n is equal to what you have assigned to precision. Precision number is define after a dot .

#####Example:

my_printf("%.2f\n", 2.0012);

will result to

2.00

For %f specifier type, precision number is used to display only n after the dot n of the float To know more about the precision, please go there : http://man7.org/linux/man-pages/man3/sprintf.3.html

####Specifiers type:

Specifier typeOutput format
d or iSigned decimal integer
uUnsigned decimal integer
oUnsigned octal integer
xUnsigned hexadecimal integer
XUnsigned hexadecimal integer (uppercase)
fDecimal floating point, lowercase
eScientific notation (mantissa/exponent), lowercase
EScientific notation (mantissa/exponent), uppercase
cCharacter
sString of characters
pPointer address
nLenght of string
%Escape % char

####Length Modifier:

Length ModifierType
lllong long int or unsigned long long int
llong int or unsigned long int
hhsigned char or unsigned char
hshort int or unsigned short int
jintmax_t or uintmax_t
zsize_t or ssize_t
tptrdiff_t

About

Implementation of C function : printf

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages