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.
This library supports the following conversions:
%c: Prints a single character.%s: Prints a string (as defined by the common C convention).%p: Thevoid *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.
To compile the library, clone the repository and run make:
git clone https://github.com/sdadak42/ft_printf.git
cd ft_printf
makeThis will generate the libftprintf.a library file.
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.
To use ft_printf in your project, include the header file and link the library during compilation:
-
Include
ft_printf.hin your C file:#include "ft_printf.h"
-
Compile your code with
libftprintf.a:cc -Wall -Wextra -Werror main.c libftprintf.a -o my_program
#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