https://github.com/ejarvinen/42ft_printf
A custom printf() function from the C Standard Library
https://github.com/ejarvinen/42ft_printf
variadic-functions
Last synced: 4 months ago
JSON representation
A custom printf() function from the C Standard Library
- Host: GitHub
- URL: https://github.com/ejarvinen/42ft_printf
- Owner: ejarvinen
- Created: 2024-10-21T07:04:21.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-01-31T17:28:13.000Z (5 months ago)
- Last Synced: 2025-01-31T18:30:40.126Z (5 months ago)
- Topics: variadic-functions
- Language: C
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 42Ft_printf
## Introduction
Welcome to **ft_printf**! The goal of this project is to reimplement the `printf()` function from the C standard library. This exercise introduced me to variadic functions in C and helped me structure extensible and efficient code.## Mandatory Requirements
- Must be written in C and adhere to the 42 coding norm.
- All heap-allocated memory must be properly freed to avoid leaks.
- The project must compile with `cc` using the flags: `-Wall -Wextra -Werror`.
- Makefile must support the following rules: `all`, `clean`, `fclean` and `re`.
- The final library must be named `libftprintf.a` and be created using `ar` (not `libtool`).
- The function `ft_printf()` will be compared against the standard `printf()`.## Installation
To set up and use **ft_printf**, follow these steps:
```
# Clone the repository
git clone https://github.com/ejarvinen/42Ft_printf.git
cd 42Ft_printf# Compile library
make# Include ft_printf in your project
gcc -Wall -Wextra -Werror your_program.c -L. -lftprintf -o your_program
```
## Features
**ft_printf** supports the following conversions:
| **Specifier** | **Description** |
| :-----: | :-----|
| `%c` | Prints a single character |
| `%s` | Prints a string |
| `%p` | Prints a pointer address in hexadecimal |
| `%d` | Prints a decimal (base 10) integer |
| `%i` | Prints an integer (base 10) |
| `%u` | Prints an unsigned decimal number |
| `%x` | Prints a number in lowercase hexadecimal (base 16) |
| `%X` | Prints a number in uppercase hexadecimal (base 16) |
| `%%` | Prints a percent sign |## Compilation & Usage
To use `ft_printf()` in your project:
```
#include "libftprintf.h"int main()
{
ft_printf("Hello, %s! You have %d new messages.\n", "User", 5);
return 0;
}
```
Compile and link against the library:
```
cc main.c -L. -lftprintf -o test_printf
./test_printf
```