ft_printf is a C project that aims to recreate the C standard library function printf()
. This project is part of the 42 coding school curriculum and helps students understand variadic functions, string manipulation, and memory management in C.
- Supports basic format specifiers:
%c
,%s
,%p
,%d
,%i
,%u
,%x
,%X
,%n
. - Handles flags:
-
,0
,.
and*
. - Handles field width and precision.
- Implements a custom buffer for efficient output.
- A Unix-based operating system (macOS, Linux, or WSL on Windows)
- GCC compiler
make
utility
- Clone the repository:
git clone https://github.com/JosephKiragu/ft_printf.git
- Change into the project directory:
cd ft_printf
- Compile the project using the provided
Makefile
:
make
- Include the header file
ft_printf.h
in your C source files where you want to use theft_printf
function.
#include "ft_printf.h"
- Use the
ft_printf
function in the same way as the standardprintf()
function. Here's an example:
#include "ft_printf.h"
int main(void)
{
int number = 42;
char *string = "Hello, World!";
ft_printf("This is an integer: %d\n", number);
ft_printf("This is a string: %s\n", string);
return 0;
}
- Compile your program with the ft_printf object files:
gcc -Wall -Wextra -Werror -I./ -o your_program your_program.c libftprintf.a
- Run your program:
./your_program
The project comes with a test suite. To run the tests, follow these steps:
- Compile the test program:
make test
- Run the test program:
./test_ft_printf