#Exploring the C programming language - Rewrite Printf
This project creates our version, _printf, of the C library function printf. Printf formats data and converts it to a character string and outputs to stdout
.
##How To Use
$ git clone [email protected]:j-tyler/printf.git
$ gcc -Wall -Werror -Wextra -pedantic *.c
Compile everything within the directory and use _printf in your code.
###Declaration int _printf(const char *format, ...)
###Example
_printf("My %s is %d", "favorite number", 8);
$ My favorite number is 8
##Completed Features
###Format tags format tags must follow the format of [flags][width][.precision][length]specifier
specifier | output |
---|---|
c | characters |
s | string of characters |
i or d | signed decimal int |
u | unsigned decimal int |
o | signed octal |
x | unsigned hexadecimal int |
X | unsigned hexadecimal int (Upper Case) |
b | Binary |
p | pointer address |
Flags | Effected Specifers | Description and Examples |
- | d, i, u, o, x, X, b, c, s |
Left justify_printf("A%3dlast", 5); _printf("A%-3dlast", 5); output $ A 5last $ A5 last |
+ | d, i |
Forces proceed to with a sign even if positive_printf("A%dlast", 5); _printf("A%+dlast", 5); output $ A5last $ A+5last |
(space) | d, i |
if no sign is given, proceed with space
_printf("A%dlast", 5); _printf("A% dlast", 5); output $ A5last $ A 5last |
# | o, x, X |
Used with o, x or X specifiers the value is preceded with 0, 0x,or 0X respectively for values different than zero.
_printf("%o, 1"); _printf("%#o, 1"); output $1 $01 |
0 | d, i, u, o, x |
left pad with spaces with 0
_printf("A%3dlast", 5); _printf("A%03dlast", 5); output $ A 5last $ A005last |
width | Effected Specifers | Description and Examples |
- | d, i, u, o, x, X, b, c, s |
minimum number to be printed_printf("A%dlast", 5); _printf("A%3dlast", 5); output $ A5last $ A 5last |
.percision | Effected Specifers | Description and Examples |
- | d, i, u, o, x, X, s |
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._printf("A%dlast", 5); _printf("A%.3dlast", 5); output $ A5last $ A005last For s − this is the maximum number of characters to be printed. _printf("A%s", "Holberton"); _printf("A%.3s", "Holberton"); output $ Holberton $ Hol |
##Contributors Justin Marsh - Github || Twitter || email
Richard Sim - Github || Twitter || email
##Want to be contributor? reach out to any of the Contributors