ft_printf is a project that aims to mimic the behavior of the original printf function from the C standard library. The project is part of the 42 curriculum and is designed to help students gain a deeper understanding of variadic functions, parsing, and string manipulation in C.
To use the libftprintf
library in your projects, follow these steps:
- Clone the ft_printf repository:
git clone https://github.com/abouabra/42-ft_printf.git
- Navigate to the ft_printf directory:
cd 42-ft_printf
- Compile the library using the provided Makefile:
make
. This will generate thelibftprintf.a
static library file. - Link
libftprintf.a
to your project at compile time. You can do this by including the library in your compilation command or by adding it to your project's Makefile.
To use the functions provided by the ft_printf library, include the ft_printf.h
header file in your source code:
#include <stdio.h>
#include "ft_printf.h"
int main(void)
{
char *str = "Hello, World!";
int len = ft_strlen(str);
ft_printf("Length of string: %d\n", len);
return (0);
}
- Compile your source code with the
libftprintf.a
library:
gcc -o example example.c -L. -lft
- Run the compiled program:
./example
- The output should be:
Length of string: 13
The following conversion specifiers are handled:
Specifier | Description |
---|---|
%c | Character |
%s | String |
%p | Pointer |
%d | Decimal |
%i | Integer |
%u | Unsigned integer |
%x | Hexadecimal |
%X | Hexadecimal |
%% | Percentage |
Specifier | Description |
---|---|
%- | left-justify |
%0 | zero padding |
%. | precision |
%# | alternate form |
%+ | always show sign |
%space | space before positive numbers |
If you have any suggestions or improvements, feel free to open an issue or submit a pull request.