- Introduction
- Important Concepts
- Key Learning Outcomes
- Objectives
- Common Instructions
- Project Requirements
- Installation / Compile / Run
- Example Usage
- Additional Resources
The ft_printf
project aims to reimplement the standard C library function printf
. It involves parsing a format string and handling various format specifiers to print different types of arguments. This project provides a deeper understanding of variadic functions, formatted output, and string manipulation in C.
- Variadic Functions: Functions that accept a variable number of arguments, using
stdarg.h
. - Format Specifiers: Characters that define the type and format of the data to be printed, such as
%d
for integers,%s
for strings, etc. - Buffer Management: Efficiently handling buffers to store the formatted output before printing.
- Parsing Strings: Learn to parse and interpret format strings to identify and handle different format specifiers.
- Handling Variadic Arguments: Understand how to use
va_list
,va_start
,va_arg
, andva_end
to handle variadic arguments. - Formatted Output: Gain skills in formatting different types of data and managing output buffers.
- Error Handling: Develop strategies for managing errors and edge cases in string formatting and output.
- Implement Basic Specifiers: Handle basic format specifiers like
%c
,%s
,%d
,%i
,%u
,%x
, and%X
. - Advanced Specifiers: Implement more complex specifiers like
%p
for pointers and handle flags, width, and precision. - Buffer Management: Implement efficient buffer management to construct the formatted string before output.
- Error Handling: Ensure robust error handling for invalid format strings and specifiers.
- Code Norm: Adhere to the 42 coding standard.
- Memory Management: Properly manage all heap-allocated memory to avoid leaks.
- Makefile: Provide a Makefile with rules for
all
,clean
,fclean
, andre
. - No Global Variables: Use only local variables.
The ft_printf
function should mimic the behavior of the standard printf
function. It should handle the following specifiers:
%c
: Character%s
: String%p
: Pointer%d
/%i
: Integer%u
: Unsigned integer%x
/%X
: Hexadecimal
- ⬇️ Clone the repository:
git clone https://github.com/lbelet/printf.git cd ft_printf
- 🔧 Compile the project:
make
- 🛠️ Compile with a test file:
gcc -o test_ft_printf test_ft_printf.c libftprintf.a
▶️ Run the test program:./test_ft_printf
#include "ft_printf.h"
int main() {
int num = 42;
char *str = "Hello, World!";
ft_printf("Number: %d, String: %s\n", num, str);
return 0;
}
This will output:
Number: 42, String: Hello, World!