Skip to content

A custom printf() implementation in C, developed as part of the 42 Network programming curriculum, showcasing string formatting and variadic function techniques.

Notifications You must be signed in to change notification settings

yomazini/42cursus-ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–¨οΈ ft_printf | 42 School Project

Because standard printf is too mainstreamπŸ˜‰

42 School Badge Norminette Score

"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

  • πŸŽ₯ 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.
  • πŸŽ₯ Duration: Approx. 13 minutes
  • πŸ› οΈ Overview: A more advanced look at variadic functions, focusing on real-world coding examples and detailed implementation tips.

πŸ“š Written Resources

  • 🌐 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

  • πŸ–ΌοΈ 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:
git clone https://github.com/yomazini/42cursus-ft_printf.git
  1. Navigate to the project directory:
cd 42cursus-ft_printf
  1. Compile the library:
# Compile the library
make

# Clean object files
make clean

# Clean everything
make fclean

# Recompile
make re

# Test
make test

πŸ’‘ Implementation Details

πŸ” Core Components

🧠 Key Concepts Demonstrated

  • Variadic function handling with <stdarg.h>
  • 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

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

πŸ’» Compilation

To use in your project:

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


"In printf we trust, one character at a time!" πŸ˜„

About

A custom printf() implementation in C, developed as part of the 42 Network programming curriculum, showcasing string formatting and variadic function techniques.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published