Skip to content
jzelada97Public

About

Custom implementation of printf() in C using variadic functions. Supports %c, %s, %p, %d, %i, %u, %x, %X conversions (42 School).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ft_printf

A custom implementation of printf() from the C standard library

Reimplementation of printf() as a static library (libftprintf.a), built from scratch using variadic functions (stdarg.h). Handles formatted output with type-safe argument parsing.


Supported Conversions

Specifier Output
%c Single character
%s String
%p Pointer address (hex)
%d Signed decimal integer
%i Signed integer (base 10)
%u Unsigned decimal integer
%x Hexadecimal (lowercase)
%X Hexadecimal (uppercase)
%% Literal %

Build

make        # compiles libftprintf.a
make clean  # removes .o files
make fclean # removes .o and .a files
make re     # full recompile

Usage

#include "ft_printf.h"

int main(void)
{
    ft_printf("Hello %s, you are %d years old\n", "world", 42);
    ft_printf("Pointer: %p\n", &main);
    ft_printf("Hex: %x | Upper: %X\n", 255, 255);
    return (0);
}

Compile with the library:

cc -Wall -Wextra -Werror main.c -L. -lftprintf -o my_program

Architecture

ft_printf/
├── ft_printf.c          # Core dispatcher — parses format string and routes to handlers
├── ft_printf.h          # Header with prototypes
├── ft_print_char.c      # %c handler
├── ft_print_string.c    # %s handler
├── ft_print_number.c    # %d / %i handler
├── ft_print_unsigned.c  # %u handler
├── ft_print_hex.c       # %x / %X handler
├── ft_print_pointer.c   # %p handler
└── Makefile

How it works

  1. ft_printf iterates through the format string character by character
  2. When % is found, it reads the next character to determine the conversion
  3. The appropriate handler is called, which writes to stdout using write()
  4. Each handler returns the number of characters printed
  5. The total count is returned (matching printf behavior)

Context

Developed as part of the 42 Madrid curriculum. The project focuses on variadic functions, formatted output, and modular C programming.

About

Custom implementation of printf() in C using variadic functions. Supports %c, %s, %p, %d, %i, %u, %x, %X conversions (42 School).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages