Skip to content

🧡 A homemade printf() clone β€” because C wasn’t hard enough already πŸ˜… 🎯 Handles %c, %s, %p, %d, %i, %u, %x, %X, and even %% like a pro! πŸ’Ύ Built with love, variadic magic, and way too many segfaults 🧨

Notifications You must be signed in to change notification settings

Frontendab/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧡 ft_printf

Because ft_putnbr() and ft_putstr() aren’t enough πŸ˜‰


πŸ“˜ Introduction

The ft_printf project is about re-implementing the famous C function printf().
It teaches you how to handle a variable number of arguments using variadic functions in C.

Once completed, you’ll have your own version of printf() ready to use in future projects β€”
and you’ll understand one of the most powerful formatting tools in C.


🧠 Purpose

  • Discover and understand variadic functions (va_start, va_arg, etc.)
  • Learn to format and print data of various types.
  • Strengthen your skills in modular code design, memory management, and error handling.
  • Build a static library (libftprintf.a) that can be reused in other projects.

βš™οΈ Mandatory Requirements

Program name libftprintf.a
Turn in files Makefile, *.h, *.c, and subfolder equivalents
Makefile rules NAME, all, clean, fclean, re
External functions malloc, free, write, va_start, va_arg, va_copy, va_end
Libft allowed βœ… Yes
Bonus included? ❌ No (mandatory part only)

🧩 Prototype

int ft_printf(const char *format, ...);

πŸ–¨οΈ Supported Conversions

Your implementation must handle the following format specifier:

Specifier Description
%c Prints a single character
%s Prints a string
%p Prints a pointer address in hexadecimal
%d Prints a signed decimal integer
%i Prints a signed integer (same as %d)
%u Prints an unsigned decimal integer
%x Prints a number in lowercase hexadecimal
%X Prints a number in uppercase hexadecimal
%% Prints a literal percent sign

🧱 Project Structure

β”œβ”€β”€ πŸ“ includes
β”‚   └── ⚑ ft_printf.h
β”œβ”€β”€ πŸ“ libft
β”‚   β”œβ”€β”€ πŸ“„ Makefile
β”‚   β”œβ”€β”€ πŸ“„ *.c
β”‚   └── ⚑ libft.h
β”œβ”€β”€ πŸ“ src
β”‚   β”œβ”€β”€ πŸ“„ ft_check_is_find.c
β”‚   β”œβ”€β”€ πŸ“„ ft_print_base.c
β”‚   β”œβ”€β”€ πŸ“„ ft_print_p.c
β”‚   β”œβ”€β”€ πŸ“„ ft_printf.c
β”‚   β”œβ”€β”€ πŸ“„ ft_printux_x.c
β”‚   β”œβ”€β”€ πŸ“„ ft_putchar.c
β”‚   └── πŸ“„ ft_putstr.c
β”œβ”€β”€ πŸ“„ Makefile
β”œβ”€β”€ πŸ“ README.md
└── πŸ“• en.subject.pdf

🧩 Structure may vary depending on your implementation β€” keep it modular and readable!

πŸ—οΈ Compilation

Your Makefile must:

  • Compile source files with the following flags:
cc -Wall -Wextra -Werror
  • Create a static library called libftprintf.a
  • Avoid unnecessary relinking

Commands

Command Description
make Compile and build the library
make clean Remove object files
make fclean Remove object files and the library
make re Rebuild everything from scratch

πŸ§ͺ Testing

Example test program:

#include "includes/ft_printf.h"
#include <stdio.h>

int main(void)
{
    int n1 = ft_printf("My ft_printf: %d %s %p %x %%\n", 42, "Hello", (void *)0x1234, 255);
    int n2 = printf("Original printf: %d %s %p %x %%\n", 42, "Hello", (void *)0x1234, 255);
    printf("Returned: ft_printf=%d | printf=%d\n", n1, n2);
}

Compile with:

cc main.c libftprintf.a

Expected output:

My ft_printf: 42 Hello 0x1234 ff %
Original printf: 42 Hello 0x1234 ff %
Returned: ft_printf=35 | printf=38

🧹 Norm & Memory

  • Code must comply with the 42 Norm 🧾
  • No memory leaks or unexpected crashes (segfaults, double frees, etc.)
  • Every allocated memory must be properly freed when necessary

🧾 Evaluation Checklist (Mandatory Part)

βœ… Handles all mandatory conversions

βœ… Correctly returns the number of printed characters

βœ… Works identically to printf in standard cases

βœ… Compiles with -Wall -Wextra -Werror

βœ… Passes Norminette checks

βœ… No memory leaks or crashes

βœ… Library correctly created using ar

πŸ§‘β€πŸ’» Author

Ayoub Sadouri

42 Network – ft_printf project

β€œA good printf is not about printing β€” it’s about precision.”

πŸ“¬ Contact

If you’re looking to build robust, scalable C applications or integrate low-level components into your web projects β€” let’s connect and collaborate!

https://ayoubsadouri.com

⭐ Don’t forget to star the repo if you find it helpful!

About

🧡 A homemade printf() clone β€” because C wasn’t hard enough already πŸ˜… 🎯 Handles %c, %s, %p, %d, %i, %u, %x, %X, and even %% like a pro! πŸ’Ύ Built with love, variadic magic, and way too many segfaults 🧨

Topics

Resources

Stars

Watchers

Forks