- Prototype:
int ft_printf(const char *, ...); - Handles the following conversions:
%c: Prints a single character.%s: Prints a string (as defined by the common C convention).%p: Prints avoid *pointer in hexadecimal format.%d: Prints a decimal (base 10) integer.%i: Prints an integer in base 10.%u: Prints an unsigned decimal (base 10) number.%x: Prints a number in hexadecimal (base 16) lowercase format.%X: Prints a number in hexadecimal (base 16) uppercase format.%%: Prints a percent sign.
- Evaluated against the behavior of the original
printf, ensuring compatibility.
- Buffer Management: Do not implement the original
printf's buffer management. - Library Creation:
- Use the
arcommand to create the library. - The use of the
libtoolcommand is strictly forbidden. - The library file
libftprintf.amust be created at the root of the repository.
- Use the
- Compilation: Ensure your implementation compiles and functions as intended.
- Naming: Use the function name
ft_printffor all implementations.
- Variadic Arguments: The function uses variadic arguments to process the format string and corresponding arguments passed to
ft_printf. - Output Management: The behavior mimics
printf, ensuring correct formatting, precision, and output for all supported conversions. - Edge Cases: Your implementation will be tested against various edge cases to ensure robustness and compatibility with
printf.
ft_printf was created because standard functions like ft_putnbr() and ft_putstr() are not sufficient for complex formatted output. This project provides a deeper understanding of how formatting works and demonstrates the process of creating a robust, reusable library.
- Clone the repository and navigate to the root directory.
- Compile the library by running:
This will create
make
libftprintf.ain the root directory. - Include the library in your project by linking it during compilation:
gcc -o your_program your_program.c -L. -lftprintf
- Call
ft_printfin your code just like the originalprintf.
#include "ft_printf.h"
int main() {
ft_printf("Character: %c\n", 'A');
ft_printf("String: %s\n", "Hello, World!");
ft_printf("Pointer: %p\n", (void *)&main);
ft_printf("Decimal: %d\n", 42);
ft_printf("Integer: %i\n", -42);
ft_printf("Unsigned: %u\n", 12345);
ft_printf("Hexadecimal (lowercase): %x\n", 255);
ft_printf("Hexadecimal (uppercase): %X\n", 255);
ft_printf("Percent Sign: %%\n");
return 0;
}- You cannot use the
libtoolcommand. - The library must be created using
arand placed in the root directory aslibftprintf.a.
To test your implementation, compare the outputs of ft_printf and the original printf with the same format strings and arguments. Ensure edge cases are handled gracefully.