https://github.com/link-wolf/ft_printf
42 project - Recoded C-printf
https://github.com/link-wolf/ft_printf
42 42born2code 42school c macos
Last synced: about 2 months ago
JSON representation
42 project - Recoded C-printf
- Host: GitHub
- URL: https://github.com/link-wolf/ft_printf
- Owner: Link-Wolf
- Created: 2022-03-03T07:54:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-27T13:33:05.000Z (almost 2 years ago)
- Last Synced: 2025-01-27T12:49:41.557Z (over 1 year ago)
- Topics: 42, 42born2code, 42school, c, macos
- Language: C
- Homepage:
- Size: 277 KB
- Stars: 1
- 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
A C project to 'simply' recode printf
Report Bug
·
Request Feature
Table of Contents
## About The Project
This project is focused on recode the libc's printf function and compile it as a C library
### Mandatory part (conversions)
- `%c` -> print a single character.
- `%s` -> print a string of characters.
- `%p` -> The void \* pointer argument is printed in hexadecimal.
- `%d` -> print a decimal (base 10) number.
- `%i` -> print an integer in base 10.
- `%u` -> print an unsigned decimal (base 10) number.
- `%x` -> print a number in hexadecimal (base 16), with lowercase.
- `%X` -> print a number in hexadecimal (base 16), with uppercase.
- `%%` -> print a percent sign.
### Bonus part
- Managing any combination of the following flags: `-0.` and minimum field width
with all conversions
- Managing all the following flags: `#+` + the space one
## Getting Started
Because it's a simple C library, there isn't much to say here
### Prerequisites
Having a C compiler like cc, gcc or clang
### Installation
1. Clone the repo
```sh
git clone https://github.com/Link-Wolf/ft_printf.git
```
2. Compile the project
```sh
cd ft_printf; make
```
3. Include ft_printf in your C project
```c
#include "include/ft_printf.h
```
4. Compile your project with the ft_printf library
```sh
gcc your_project.c -L. -lftprintf
```
## Usage
Use the ft_printf function as you'd use the native printf (for the available conversions)
As ft_printf doesn't include all printf features, it is way more fast than printf (for example for debugging purposes, when a segmentation fault occurs after a printf, it doesn't have enough time to be executed before the segfault)
```c
char c = 'a';
char *s = "wesome";
int d = 42;
int i = 69;
unsigned int u = 30903;
int x = 58;
int x_two = 424;
ft_printf("Char : %c\n", c);
ft_printf("String : %s\n", s);
ft_printf("Pointer : %p\n", s);
ft_printf("Decimal number : %d\n", d);
ft_printf("Integer : %i\n", i);
ft_printf("Unsigned decimal number : %u\n", u);
ft_printf("Hexadecimal in lowercase : %x\n", x);
ft_printf("Hexadecimal in uppercase : %X\n", x_two);
ft_printf("Percent : %%\n");
```
Output
```
Char : a$
String : wesome$
Pointer : 0x10a9aeeb4$
Decimal number : 42$
Integer : 69$
Unsigned decimal number : 30903$
Hexadecimal in lowercase : 3a$
Hexadecimal in uppercase : 1A8$
Percent : %$
```
## Roadmap
- [x] Add bonus features
See the [open issues](https://github.com/Link-Wolf/ft_printf/issues) for a full list of proposed features (and known issues).
## Contributing
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request