Welcome to ft_printf! ๐ This project is part of the 42 curriculum, where you will implement your own version of the C standard library function printf
. By doing this, you'll gain a deeper understanding of variadic functions, formatted output, and string manipulation in C. ๐ ๏ธ
- Basic Conversion Specifiers: Supports
%c
,%s
,%p
,%d
,%i
,%u
,%x
, and%X
. - Bonus Features: Add support for additional flags like
#
,0
,-
,+
. - Memory Management: Proper handling of memory allocation and freeing for dynamic strings.
int ft_printf(const char *format, ...);
format
: The string containing the text to be written to the standard output, optionally containing format specifiers that are replaced by the values of additional arguments.
ft_printf("Hello, %s!\n", "world");
ft_printf("Number: %d, Hex: %x\n", 42, 42);
|-- srcs/
| |-- ft_printf.c # Main ft_printf logic
| |-- ft_printf.h # Header file with prototypes and macros
| |-- ft_putchar_n_count.c # Helper function to print a character and count it
| |-- ft_putstr_n_count.c # Helper function to print a string and count it
| |-- ft_putnbr_n_count.c # Helper function to print a number and count it
| |-- ft_puthexa_n_count.c # Helper function to print a hexadecimal number and count it
| |-- ft_putptr_n_count.c # Helper function to print a pointer address and count it
|-- Makefile # Makefile to compile the project
|-- main.c # Test file for ft_printf implementation
To compile and test your ft_printf
function, use the provided Makefile:
make
./ft_printf
You can also create your own test cases in main.c
to verify the behavior of your implementation against the standard printf
function.
By completing this project, you will:
- Gain a deep understanding of how formatted output functions work in C.
- Improve your skills in handling variable argument lists with
va_list
. - Enhance your ability to manage and format different data types.
For those looking to go above and beyond, consider adding support for the following:
- Additional Flags: Implement support for
#
,0
,-
,+
. - Width and Precision: Handle the width and precision fields in the format specifiers.
This project is released under the MIT License. Feel free to fork, learn, and contribute! ๐ค
Happy coding! ๐งโ๐ป