A custom implementation of the standard C printf function, compiled as a static library that can be reused in other projects.
This library implements the ft_printf function with support for the following format specifiers:
%c- Character%s- String%d/%i- Integer (decimal)%u- Unsigned integer%x/%X- Hexadecimal (lowercase/uppercase)%p- Pointer address
To compile the library:
makeThis will create ftprintf.a - a static library file containing all the compiled code.
To clean up object files:
make cleanTo remove everything (object files and library):
make fcleanTo rebuild from scratch:
make reCopy the library and header to your project, then compile together:
cc -Wall -Wextra -Werror -I/path/to/ft_printf/include your_file.c /path/to/ft_printf/ftprintf.a -o your_programIn your project's Makefile, include the ft_printf library:
# Variables
FT_PRINTF_PATH = /path/to/ft_printf
FT_PRINTF_LIB = $(FT_PRINTF_PATH)/ftprintf.a
# Compilation flags
CFLAGS = -Wall -Wextra -Werror -I$(FT_PRINTF_PATH)/include
# Your program
your_program: your_file.o $(FT_PRINTF_LIB)
cc $(CFLAGS) your_file.o $(FT_PRINTF_LIB) -o your_program
your_file.o: your_file.c
cc $(CFLAGS) -c your_file.c -o your_file.o- Copy the entire
ft_printfdirectory into your project - In your Makefile, add:
CFLAGS += -I./ft_printf/include
LIBS = ./ft_printf/ftprintf.a
your_program: your_file.o $(LIBS)
cc $(CFLAGS) your_file.o $(LIBS) -o your_program#include "ft_printf.h"
int main(void)
{
ft_printf("Hello, %s!\n", "World");
ft_printf("Number: %d, Hex: %x\n", 42, 42);
ft_printf("Pointer: %p\n", (void *)&main);
return (0);
}ft_printf/
├── Makefile # Build configuration
├── include/
│ └── ft_printf.h # Header file with ft_printf declaration
└── src/
├── ft_printf.c # Main printf function
├── ft_strchr.c # Character search utility
├── len_int_nbr.c # Integer length calculator
├── write_char.c # Character output handler
├── write_hex.c # Hexadecimal output handler
├── write_int_nbr.c # Integer output handler
├── write_ptr.c # Pointer output handler
├── write_str.c # String output handler
└── write_uns_int_nbr.c # Unsigned integer output handler
- The library is compiled with
-Wall -Wextra -Werrorflags for strict compilation standards - Always include the
-I./includeflag (or appropriate path) when compiling code that usesft_printf - The library creates object files (
*.o) which are cleaned withmake clean