Skip to content

Repository files navigation

printf

A custom implementation of the C printf function.

This project is part of the 42 curriculum and focuses on recreating variadic formatted output in C. In addition to the mandatory conversion specifiers, this implementation includes support for the bonus formatting flags, requiring parsing and handling of formatting behavior such as width, precision, alignment, padding, and prefixes.

The project strengthened understanding of variadic functions, string formatting, parsing, and low-level output handling.

Features

Supported conversion specifiers:

  • %c — character
  • %s — string
  • %d / %i — signed integer
  • %u — unsigned integer
  • %x / %X — hexadecimal
  • %p — pointer
  • %% — percent sign

Supported formatting features:

  • Width specifiers
  • Precision (.)
  • Left alignment (-)
  • Zero padding (0)
  • Explicit sign (+)
  • Leading space for signed values ( )
  • Alternate form (#)

Formatting behavior is parsed internally using a conversion specification structure to handle flags and formatting rules.

Build

Compile the library using:

make

This generates libftprintf.a.

Usage

Include the header in your project:

#include "ft_printf.h"

Compile and link against the library:

cc main.c -L. -lftprintf

Example:

ft_printf("Hex: %#08x\n", 42);
ft_printf("Number: %+8d\n", 123);

About

Recreation of the C printf std function.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages