Skip to content

Re-implementation of the C printf function for 42 School. Supports formatted output, variadic arguments, and custom conversions while adhering to the constraints of the 42 curriculum.

License

Notifications You must be signed in to change notification settings

x0141af92ax/ft_printf

Repository files navigation

ft_printf

A custom implementation of the standard C printf function, developed as part of the 42 Network curriculum.
This project recreates formatted output handling, variadic arguments, and type conversions without relying on the original printf.


✨ Features

  • Handles mandatory conversion specifiers:
    • %c → character
    • %s → string
    • %d / %i → signed integer
    • %u → unsigned integer
    • %x / %X → hexadecimal (lowercase / uppercase)
    • %p → pointer address
    • %% → literal %
  • Variadic argument handling with va_start, va_arg, and va_end
  • Returns the number of characters printed (like the original printf)
  • Norminette compliant and memory‑safe

📂 Project Structure

. ├── ft_printf.c # Core implementation ├── ft_printf.h # Header file ├── ft_process_format.c# Format specifier handling ├── utils/ # Helper functions (string, number printing, etc.) └── Makefile # Build rules


⚙️ Compilation

make

## 🚀 Usage

```C
#include "ft_printf.h"

int main(void)
{
    ft_printf("Hello %s! Number: %d, Hex: %x\n", "world", 42, 42);
    return 0;
}

Compile and run:

gcc main.c libftprintf.a -o test
./test

Output:

Hello world! Number: 42, Hex: 2a

🧪 Testing

Compare against the original printf:

ft_printf("FT: %d %d %d %%\n", 1, 2, 3);
printf("OG: %d %d %d %%\n", 1, 2, 3);

Expected output:

FT: 1 2 3 %
OG: 1 2 3 %

About

Re-implementation of the C printf function for 42 School. Supports formatted output, variadic arguments, and custom conversions while adhering to the constraints of the 42 curriculum.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published