https://github.com/yomazini/42cursus-ft_printf
A custom printf() implementation in C, developed as part of the 42 Network programming curriculum, showcasing string formatting and variadic function techniques.
https://github.com/yomazini/42cursus-ft_printf
1337cursus 1337school 42cursus ftprintf ftprintf42
Last synced: 18 days ago
JSON representation
A custom printf() implementation in C, developed as part of the 42 Network programming curriculum, showcasing string formatting and variadic function techniques.
- Host: GitHub
- URL: https://github.com/yomazini/42cursus-ft_printf
- Owner: yomazini
- Created: 2024-11-25T22:21:45.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-01T23:50:46.000Z (about 1 year ago)
- Last Synced: 2025-07-02T00:26:20.467Z (about 1 year ago)
- Topics: 1337cursus, 1337school, 42cursus, ftprintf, ftprintf42
- Language: C
- Homepage:
- Size: 1.45 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π¨οΈ ft_printf | 42 School Project
### Because standard `printf` is too mainstreamπ



> *"Why use standard printf when you can recreate the entire functionality from scratch?"* - Every 1337/42 Student Do π
## π― Project Overview
Welcome to my implementation of `ft_printf` - a custom printf function that replicates the behavior of the standard C library's `printf()`. This project is all about diving deep into variadic functions, type handling, and the intricate world of formatted output.
### π Key Features
- **Full Printf Functionality**: Supports multiple format specifiers
- **Robust Error Handling**: Carefully managed edge cases
- **Recursive Implementation**: Elegant and memory-efficient approach
- **Extensible Design**: Easy to understand and modify
- **No Standard Library Shortcuts**: Pure C implementation
## π Supported Format Specifiers
| Specifier | Description | Example |
|-----------|-------------|---------|
| `%c` | Single character | `ft_printf("%c", 'A')` |
| `%s` | String | `ft_printf("%s", "Hello")` |
| `%d` | Signed decimal integer | `ft_printf("%d", 1337)` |
| `%i` | Signed decimal integer | `ft_printf("%i", -17)` |
| `%u` | Unsigned decimal integer | `ft_printf("%u", 100)` |
| `%x` | Lowercase hexadecimal | `ft_printf("%x", 255)` |
| `%X` | Uppercase hexadecimal | `ft_printf("%X", 255)` |
| `%p` | Pointer address | `ft_printf("%p", &var)` |
| `%%` | Percent sign | `ft_printf("%%")` |
## π Getting Started
### Prerequisites
- Variadic Function (Recommended Resources Below)
- GCC compiler
- Make
---
## **Variadic Function Resources** π
Below is a list of resources to help you master this topic, from detailed explanations to practical implementations.
## **πΊ Video Tutorials**
### 1. [Variadic Functions by Oceano](https://www.youtube.com/watch?v=7Sph8JlRo0g)
- π₯ **Duration**: Approx. 17 minutes
- π **Overview**: Explores the basics of variadic functions, their syntax, and their practical applications. Perfect for beginners who enjoy a straightforward teaching style.
### 2. [Variadic Functions by Code Vault](https://www.youtube.com/watch?v=oDC208zvsdg)
- π₯ **Duration**: Approx. 13 minutes
- π οΈ **Overview**: A more advanced look at variadic functions, focusing on real-world coding examples and detailed implementation tips.
## **π Written Resources**
### 3. [Variadic Functions in C on GeeksforGeeks](https://www.geeksforgeeks.org/variadic-functions-in-c/)
- π **Type**: Article
- π **Overview**: Covers the theoretical foundation, with code examples illustrating how variadic functions work. Includes topics like `stdarg.h` and the use of macros for handling arguments.
## **π Interactive Explanation**
### 4. [Detailed Variadic Function Explanation on Miro](https://miro.com/app/board/uXjVN-42a5k=/)
- πΌοΈ **Type**: Interactive Board
- π§© **Overview**: A visual and detailed explanation of variadic functions. Great for those who learn best through diagrams and hands-on exploration.
---
### Installation
1. Clone the repository:
```bash
git clone https://github.com/yomazini/42cursus-ft_printf.git
```
1. Navigate to the project directory:
```bash
cd 42cursus-ft_printf
```
1. Compile the library:
```bash
# Compile the library
make
# Clean object files
make clean
# Clean everything
make fclean
# Recompile
make re
# Test
make test
```
## π‘ Implementation Details
### π Core Components
- **Main Function**: [ft_printf](ft_printf.c) - The entry point that handles format string parsing
- **Format Handler**: [ft_format_pf](ft_printf.c) - Dispatches to specific type handlers
- **Type-Specific Handlers**:
- [ft_putchar_pf](ft_putchar_pf.c): Character output
- [ft_putstr_pf](ft_putstr_pf.c): String output
- [ft_putnbr_pf](ft_putnbr_pf.c): Integer output
- [ft_puthex_pf](ft_puthex_pf.c): Hexadecimal output
- [ft_putunbr_pf](ft_putunbr_pf.c): Unsigned integer output
- [ft_putadr_pf](ft_putadr_pf.c): Pointer address output
### π§ Key Concepts Demonstrated
- Variadic function handling with ``
- Recursive printing techniques
- Dynamic type conversion
- Error management
- Memory-efficient character-by-character output
## π¬ Interesting Challenges
- Handling integer edge cases (e.g., INT_MIN)
- Implementing hexadecimal conversion
- Managing pointer address printing
- Efficient recursive algorithms
- Robust error handling
## π Usage Example
```c
#include "ft_printf.h"
int main(void) {
int num = 42;
char *str = "Hello, 42!";
ft_printf("Character: %c\n", 'A');
ft_printf("String: %s\n", str);
ft_printf("Decimal: %d\n", num);
ft_printf("Hex (lowercase): %x\n", num);
ft_printf("Hex (uppercase): %X\n", num);
ft_printf("Pointer: %p\n", (void*)&num);
return (0);
}
```
## π§ͺ Testing
Recommended testing tools:
- Custom test cases (Go Crazy π)
- [printf-tester](https://github.com/Tripouille/printfTester)
## π» Compilation
To use in your project:
```bash
# with main.c File
make test
```
## π Best Practices Demonstrated
- Modular design
- Extensive error checking
- Memory safety
- Efficient algorithms
- Clear, readable code
## π Performance Considerations
- Minimal memory allocation
- Recursive algorithms with O(log n) complexity
- No unnecessary buffer usage
## π What I Learned
- Advanced C programming techniques
- Variadic function implementation
- Deep understanding of type conversion
- System-level output handling
## π€ Contribution
Feel free to:
- Open issues
- Submit pull requests
- Provide feedback
## π Author
Made with βοΈ and βοΈβοΈβοΈ by Youssef Mazini (ymazini)
- 42 Intra: [ymazini](https://profile.intra.42.fr/users/ymazini)
- GitHub: [yomazini](https://github.com/yomazini)
---
> *"In printf we trust, one character at a time!"* π