Skip to content

A custom implementation of the standard C library function printf. Focuses on handling variadic arguments and data formatting.

Notifications You must be signed in to change notification settings

sdadak42/ft_printf

Repository files navigation

ft_printf

Description

ft_printf is a custom implementation of the standard C library function printf. This project mimics the behavior of the original function, allowing for formatted output to the standard output. It is part of the 42 curriculum and serves as an exercise in variable argument handling (va_list) and string manipulation.

Features

This library supports the following conversions:

  • %c : Prints a single character.
  • %s : Prints a string (as defined by the common C convention).
  • %p : The void * pointer argument has to be printed in hexadecimal format.
  • %d : Prints a decimal (base 10) number.
  • %i : Prints an integer in base 10.
  • %u : Prints an unsigned decimal (base 10) number.
  • %x : Prints a number in hexadecimal (base 16) lowercase format.
  • %X : Prints a number in hexadecimal (base 16) uppercase format.
  • %% : Prints a percent sign.

Installation

To compile the library, clone the repository and run make:

git clone https://github.com/sdadak42/ft_printf.git
cd ft_printf
make

This will generate the libftprintf.a library file.

Makefile Rules

  • make : Compiles the library.
  • make clean : Removes object files.
  • make fclean : Removes object files and the library.
  • make re : Re-compiles the library from scratch.

Usage

To use ft_printf in your project, include the header file and link the library during compilation:

  1. Include ft_printf.h in your C file:

    #include "ft_printf.h"
  2. Compile your code with libftprintf.a:

    cc -Wall -Wextra -Werror main.c libftprintf.a -o my_program

Example

#include "ft_printf.h"

int main(void)
{
    ft_printf("Hello, %s!\n", "World");
    ft_printf("Character: %c\n", 'A');
    ft_printf("Number: %d\n", 42);
    ft_printf("Hex: %x\n", 255);
    return (0);
}

Developed by sdadak for 42 Istanbul

About

A custom implementation of the standard C library function printf. Focuses on handling variadic arguments and data formatting.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published