ft_dprintarg.c | ||
ft_dprintflag.c | ||
ft_dprintl_base.c | ||
ft_dprintptr.c | ||
ft_dprintul_base.c | ||
ft_dprintul.c | ||
ft_dprintx.c | ||
ft_dprintX.c | ||
ft_isarg.c | ||
ft_isdigit.c | ||
ft_printf.c | ||
ft_printf.h | ||
ft_putchar_fd.c | ||
ft_putstr_fd.c | ||
ft_skipflag.c | ||
ft_strlen.c | ||
ft_vdprintf.c | ||
Makefile | ||
README.md | ||
subject.pdf |
ft_printf
This is my implementation of the ft_printf project for the 42 school.
Description
ft_printf is a function that replicates the functionality of the standard C printf function, allowing for formatted printing of strings and variables. The project requires the implementation of the ft_printf function in C, as well as the handling of a wide range of format specifiers and flags.
The project aims to develop students' understanding of variadic functions, formatting, and bit manipulation.
Usage
To use the ft_printf function, first compile the libftprintf.a
library by running make
in the root directory of the project.
Then, include the header file ft_printf.h
in your C program and call the ft_printf
function with the desired format string and arguments. For example: ft_printf("Hello, %s!\n", "world");
.
The function will output the formatted string to the standard output.
Supported Specifiers
The ft_printf function supports the following format specifiers:
Specifier | Description |
---|---|
%c |
Character |
%s |
String |
%p |
Pointer |
%d |
Signed decimal integer |
%i |
Signed decimal integer |
%u |
Unsigned decimal integer |
%o |
Unsigned octal |
%x |
Unsigned hexadecimal (lowercase) |
%X |
Unsigned hexadecimal (uppercase) |
%% |
Literal % |
Implementation Overview
The ft_printf function uses variadic arguments and a format string to output a formatted string to the standard output. The function first parses the format string to identify the format specifiers, then uses these to output the formatted string.
To parse the format string, the function iterates through each character in the string and performs the following actions:
if the character is not a format specifier, output it to the standard output.
To output the formatted string, the function uses a combination of standard C library functions and custom helper functions.
Concepts Learned
Through the completion of this project, I gained knowledge and experience in the following areas:
- printf feature
- va_arg
Resources
Authors
This project was created by Camille CHAUVET. If you have any questions or suggestions, feel free to contact me.