ft_printf is a custom implementation of the standard C library's printf function. The purpose of this project is to demonstrate the ability to handle variadic functions, formatting, and different data types for output. It behaves similarly to the original printf but with your own custom implementation.
This project involves the creation of a printf function that mimics the behavior of the standard C library's printf, but is fully implemented from scratch. It supports the majority of the common format specifiers such as %d, %i, %u %s, %c, %x, %X, %p and %%. The goal is to understand variadic functions and gain deeper experience with C string handling.
- Handles various format specifiers, including:
%dor%ifor integers%sfor strings%cfor characters%xor%Xfor hexadecimal numbers%ufor unsigned integers%pfor pointer addresses%%to print a literal%character.
- Flexible and customizable implementation that simulates the standard
printffunction's behavior.
- GCC or any C-compatible compiler
make
-
Clone the repository:
git clone https://github.com/yourusername/ft_printf.git cd ft_printf -
Compile the project:
make
Testing the Function To test ft_printf, create a C file that includes ft_printf.h, call the function, and print various formatted outputs.
Example main.c:
#include "ft_printf.h"
int main() {
int a = 42;
char c = 'A';
char *str = "Hello, World!";
ft_printf("Integer: %d\n", a);
ft_printf("Character: %c\n", c);
ft_printf("String: %s\n", str);
return 0;
}Example Output Given the following code:
ft_printf("Integer: %d\n", 42);
ft_printf("Character: %c\n", 'A');
ft_printf("String: %s\n", "Hello, World!");The expected output would be:
Integer: 42
Character: A
String: Hello, World!
