The printf function is one of the most versatile and well-known functions in the C language. From a testing aid to tabulation method, printf is a very powerful and important tool in every dev's kit. This project aims to recreate the behaviour of the original MacOS's printf, including its basic error management, some of its flags, minimum field width stipulation and most of its basic conversions.
A small description of the required conversion:
%cprint a single character.%sprint a string of characters.%pThe void * pointer argument is printed in hexadecimal.%dprint a decimal (base 10) number.%iprint an integer in base 10.%uprint an unsigned decimal (base 10) number.%xprint a number in hexadecimal (base 16).%%print a percent sign.
Manage any combination of the following flags:
-0.and minimum field width with all conversions- Manage all the following flags:
# +(yes, one of them is a space)
Main functions
Conversion functions
| Conversion | Description | Project |
|---|---|---|
| c | Single ascii character | Mandatory |
| s | String of characters NULL terminated | Mandatory |
| p | Pointer location converted to hexadecimal value | Mandatory |
| d | Decimal number | Mandatory |
| i | Integer in decimal base | Mandatory |
| u | Unsigned integer in decimal base | Mandatory |
| x | Unsigned number printed in lowercase hexadecimal base | Mandatory |
| X | Unsigned number printed in uppercase hexadecimal base | Mandatory |
| % | The '%' ascii character | Mandatory |
| o | Unsigned number printed in octal base | Extra |
| Flag | Description | Project |
|---|---|---|
| - | Left align the argument passed | Bonus 1 |
| 0 | Add '0' as a padding character in numeric conversions (single space is default) | Bonus 1 |
| . | Precision definition, followed by a number | Bonus 1 |
| + | Add a plus sign ('+') in the front of positive numeric conversions | Bonus 2 |
| ' ' | Add a single space (' ') in the front of positive numeric conversions | Bonus 2 |
| # | Add the corresponding prefix in front of x, X and o conversions | Bonus 2 |
| * | Add a placeholder for numeric values that shall be passed through the variadic arguments | Extra |
| Holder key | Prefix and justification flags * | Minimum Width * | Precision * | Conversion |
|---|---|---|---|---|
% |
- , 0 , + , ... |
10, 5 , ... |
., .10, .5, ... |
c, d, i, s, ... |
libftprintf requires a gcc compiler and some standard libraries.
Clone this repository in your local computer:
$> git clone https://github.com/caroldaniel/42sp-cursus_libft.git path/to/libftprintfIn your local repository, run make
$> make
makesuports 6 flags:
make allor simplymakecompiles printf in its mandatory formatmake bonuscompiles printf in its bonus formatmake cleandeletes the.ofiles generated during compilationmake fcleandeletes the.oand thelibftprintf.alibrary file generatedmake reexecutesfcleanandallin sequence, recompiling the librarymake rebonusexecutesfcleanandbonusin sequence, recompiling the library with the bonus functions
To use the libftprintf in your code you will need to include the header:
#include "libftprintf.h" When compiling your own code with libftprintf, don't forget to use the flags:
$> ... -lftprintf -L path/to/libftprintf.a -I path/to/libftprintf.h 
