Welcome to the ft_printf project! This repository contains the implementation of a custom printf()
function, a staple of C programming. This project is part of the 42 School curriculum and focuses on variadic functions, memory management, and formatted output.
- π Project Overview
- βοΈ Features
- π Project Structure
- π οΈ Makefile Usage
- π How to Use
- π Relinking and Dependencies
- β Norm Compliance
- π― Mandatory Part Only
- π Conclusion
- π¨βπ» Author
The ft_printf project replicates the functionality of the standard C printf()
function, allowing formatted output to the terminal. By handling variadic arguments and supporting multiple format specifiers, youβll gain an in-depth understanding of C's capabilities for formatted output.
The ft_printf
function supports various format specifiers, making it versatile for different types of formatted output:
- Supported Format Specifiers:
%c
: Print a single character.%s
: Print a string.%p
: Print a pointer in hexadecimal format.%d
/%i
: Print a signed decimal integer.%u
: Print an unsigned decimal integer.%x
: Print a lowercase hexadecimal number.%X
: Print an uppercase hexadecimal number.%%
: Print a literal percentage sign.
The project consists of multiple source and header files, along with the libft library, integrated into the ft_printf
implementation. Hereβs a snapshot of the project structure:
π¦ ft_printf
βββ π Makefile
βββ π include
β βββ π ft_printf.h
βββ π libft
β βββ π libft.h
β βββ π Makefile
β βββ π [Libft source files...]
βββ π src
β βββ π ft_printf.c
β βββ π [Additional source files...]
βββ π¦ libftprintf.a
The Makefile provides several commands to help with the compilation and management of your project:
Command | Description |
---|---|
make |
Compile the libftprintf.a library. |
make clean |
Remove object files. |
make fclean |
Remove object files and libraries. |
make re |
Clean and recompile everything. |
make clean
: Deletes all.o
files generated during the build process, but keeps the libraries.make fclean
: Deletes both the object files and the compiled library (libftprintf.a
).make re
: Cleans and recompiles the entire project, ensuring all files are up to date.
To use ft_printf
in your project, include the ft_printf.h
header file in your source code:
#include "ft_printf.h"
Run the following command to compile the libftprintf.a
library:
make
To use libftprintf.a
in your own project, link it during compilation:
gcc your_program.c -I./include/ -I./libft/ -L. -lftprintf -o your_program
Hereβs an example showing how to use ft_printf
in your C program:
#include "ft_printf.h"
int main(void)
{
ft_printf("Hello, %s!\n", "42");
return 0;
}
The project is designed to avoid unnecessary relinking. If changes are made to any of the source or header files in the libft
or ft_printf
directories, the Makefile will automatically detect these changes and recompile the affected files.
The project adheres to the 42 Norm standards, ensuring:
- No memory leaks: Proper memory management and freeing of allocated memory.
- No forbidden functions: Only allowed functions are used.
- Structured code: Clean, well-organized, and readable code with appropriate error handling.
- Error-free compilation: The project compiles without warnings or errors and runs without crashes.
Currently, this project includes only the mandatory part of the ft_printf assignment. The bonus features, such as additional formatting flags, field width, and precision specifiers, have not yet been implemented.
The ft_printf project is an excellent exercise in C programming, particularly for gaining a deeper understanding of variadic functions, formatted output, and manual memory management. Building this library from scratch will equip you with valuable skills that can be applied in more advanced projects down the line.
Good luck, and happy coding! π
chrrodri
42 Barcelona
Bonus version (
printf_bonus
) will be added in the future.