An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          


Link-Wolf - ft_printf
42 grade - 125 / 100
Year - 2022
stars - ft_printf
forks - ft_printf
issues - ft_printf
OS - macOS





Logo

ft_printf


Because putnbr and putstr aren’t enough

A C project to 'simply' recode printf




Report Bug
·
Request Feature


Table of Contents



  1. About The Project


  2. Getting Started


  3. Usage

  4. Roadmap

  5. Contributing

## About The Project



ft_printf header

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

(back to top)

## 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
```

(back to top)

## 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 : %$
```

(back to top)

## 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).

(back to top)

## 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

(back to top)