The ft_printf project involves recreating the standard printf() function from the C standard library. The goal is to implement a custom ft_printf() function that mimics the behavior of printf(). This project is an excellent opportunity to learn about variadic functions in C, which allow a function to accept an indefinite number of arguments.
- Reimplement the core functionality of the
printf()function. - Handle various conversions such as characters, strings, pointers, integers, unsigned integers, and hexadecimal numbers.
- Gain experience in working with variadic functions in C.
- Develop a deeper understanding of formatted output in C.
-
Implement the
ft_printf()function with the following prototype:int ft_printf(const char *, ...);
-
Your function must handle the following conversions:
%c- Print a single character.%s- Print a string.%p- Print a pointer in hexadecimal format.%dand%i- Print a decimal (base 10) integer.%u- Print an unsigned decimal (base 10) integer.%x- Print a number in hexadecimal (base 16) lowercase format.%X- Print a number in hexadecimal (base 16) uppercase format.%%- Print a percent sign.
-
Compile the library:
make
-
Clean object files:
make clean
-
Remove all generated files, including the library:
make fclean
-
Recompile everything from scratch:
make re
To use the ft_printf() function in your project, include the necessary header files and compile your program with the libftprintf.a library:
#include "ft_printf.h"
int main(void) {
// Example usage
ft_printf("Hello, ft_printf! Number: %d\n", 42);
return (0);
}To compile a program using ft_printf:
gcc -Wall -Wextra -Werror -L[path_to_libftprintf.a] -lftprintf your_program.c -o your_program