https://github.com/aaron-22766/42_ft_printf
Replica of printf with the most useful conversions and flags
https://github.com/aaron-22766/42_ft_printf
42 42-ft-printf 42born2code 42cursus 42heilbronn 42projects 42school c printf
Last synced: 7 days ago
JSON representation
Replica of printf with the most useful conversions and flags
- Host: GitHub
- URL: https://github.com/aaron-22766/42_ft_printf
- Owner: aaron-22766
- Created: 2022-11-24T09:03:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-02-22T12:00:02.000Z (over 2 years ago)
- Last Synced: 2025-11-21T13:02:59.439Z (7 months ago)
- Topics: 42, 42-ft-printf, 42born2code, 42cursus, 42heilbronn, 42projects, 42school, c, printf
- Language: C
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ft_printf
Because putnbr and putstr arenโt enough
---
## ๐ฃ About
The goal of this project is pretty straightforward. You will recode printf. You will mainly learn about using a variable number of arguments. How cool is that?? It is actually pretty cool :) You will learn what is and how to implement variadic functions. Once you validate it, you will reuse this function in your future projects.
## ๐ Usage
### Requirements
The library is written in C language and thus needs the **`gcc` compiler** and some standard **C libraries** to run.
### Instructions
**1. Compiling the library**
To compile the library, run:
```shell
$ cd path/to/printf && make
```
**2. Using it in your code**
To use the library functions in your code, simply include its header:
```C
#include "ft_printf.h"
```
**3. Link your program with libft.a**
```Makefile
PRINTF_DIR = path/to/printf
PRINTF = $(PRINTF_DIR)/libftprintf.a
$(NAME): $(PRINTF)
gcc $(PRINTF) $(MY_SRCS)...
$(PRINTF):
make -C $(PRINTF_DIR)
```
## ๐ฌ Description
Works just like printf of the `stdio` header. Because I had so much fun with this project I took the time to implement even more functions from the printf family, like dprintf, vdprintf, asprintf and vasprintf. These I added to my [massively expanded libft](https://github.com/aaron-22766/libft) which I used in all my projects later on.
### Mandatory
Implemented conversion characters are:
- `%c` Prints a single character.
- `%s` Prints a string (as defined by the common C convention).
- `%p` The void * pointer argument has to be printed in hexadecimal format.
- `%d` Prints a decimal (base 10) number.
- `%i` Prints an integer in base 10.
- `%u` Prints an unsigned decimal (base 10) number.
- `%x` Prints a number in hexadecimal (base 16) lowercase format.
- `%X` Prints a number in hexadecimal (base 16) uppercase format.
- `%%` Prints a percent sign.
### Bonus
Implemented flags:
- `-` Left-justify within the given field width; Right justification is the default (see width sub-specifier).
- `0` Left-pads the number with zeroes (0) instead of spaces when padding is specified (see width sub-specifier).
- `#` Used with x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero.
- `(space)` If no sign is going to be written, a blank space is inserted before the value.
- `+` Forces to preceed the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a - sign.
- `.` For integer specifiers (d, i, 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. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0.
Width sub-specifier:
`(number)` Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.