ft_printf
is a custom implementation of the standard C library function printf
. The goal of this project is to recreate printf
with similar functionality, handling formatted output to the standard output stream.
- Supports the following conversions:
%c
: Character%s
: String%p
: Pointer%d
/%i
: Signed decimal integer%u
: Unsigned decimal integer%x
/%X
: Unsigned hexadecimal integer (lowercase/uppercase)%%
: Percent sign
- Handles the following flags:
-
: Left justify0
: Zero-padding.precision
: Precision for strings and integers- Field width specification
To use ft_printf
, you can clone the repository and compile the source code as follows:
git clone https://github.com/pix3l-p33p3r/ft_printf.git
cd ft_printf
make
This will generate a libftprintf.a
static library that you can link with your projects.
To use ft_printf
in your C programs, include the header and link the library during compilation:
#include "ft_printf.h"
Compile your program with ft_printf
:
gcc -Wall -Wextra -Werror -L. -lftprintf your_program.c -o your_program
Here’s a quick example of how you can use ft_printf
:
#include "ft_printf.h"
int main(void)
{
ft_printf("Hello, %s!\n", "world");
ft_printf("Number: %d\n", 42);
ft_printf("Hex: %#x\n", 255);
return 0;
}
Hello, world!
Number: 42
Hex: 0xff
To run tests and verify the implementation, you can compile the main.c
file provided with test cases:
gcc -Wall -Wextra -Werror -L. -lftprintf main.c -o test_ftprintf
./test_ftprintf
ft_printf.h
: Header file containing function prototypes and macros.ft_printf.c
: The mainft_printf
function implementation.parsing.c
: Functions for parsing format specifiers.utils.c
: Utility functions used byft_printf
.Makefile
: Makefile to build the library.