My own version of printf
NOTE: This is only a partial implementation of printf as it does accomdate formatting flags
- ft_printf is a flexible, easy-to-use C library for formatted output to various output streams. The library aims to provide an alternative and customizable implementation of the widely-used printf.
- ft_printf does not use a buffer like the original.
- It handles write() errors.
- All functions have doxygen comments.
-
%s - Prints a string: The corresponding argument should be a pointer to a null-terminated character array.
Example:ft_printf("Hello, %s!\n", "world");
-
%c - Prints a char: The corresponding argument should be a character value.
Example:ft_printf("The letter is: %c\n", 'A');
-
%p - The void * pointer argument is printed in hexadecimal: The corresponding argument should be a pointer value.
Example:ft_printf("Pointer address: %p\n", &variable);
-
%d - Print a decimal (base 10) number: The corresponding argument should be an integer value.
Example:ft_printf("The number is: %d\n", 42);
-
%i - Prints an int (base 10): The corresponding argument should be an integer value.
Example:ft_printf("The integer is: %i\n", 42);
-
%u - Print an unsigned decimal (base 10) number: The corresponding argument should be an unsigned integer value.
Example:ft_printf("The unsigned number is: %u\n", 42);
-
%x - Prints hexadecimal, base 16 (lowercase): The corresponding argument should be an integer value.
Example:ft_printf("The hexadecimal number (lowercase) is: %x\n", 42);
-
%X - Prints hexadecimal, base 16 (uppercase): The corresponding argument should be an integer value.
Example:ft_printf("The hexadecimal number (uppercase) is: %X\n", 42);
-
%% - Prints a %: To include a literal '%' character in your output, use the '%%' format specifier.
Example:ft_printf("Percentage: 50%%\n");
- Clone the repository.
% git clone https://github.com/RealConrad/42printf.git ft_printf
- Enter the directory and build the library.
% cd ft_printf
% make all
- Clean object files
% make clean
An example on how to use the library:
File: main.c
#include "ft_printf.h"
int main(void) {
int value = 42;
char str[] = "Hello, World!";
ft_printf("Integer value: %d\n", value);
ft_printf("String value: %s\n", str);
return (0);
}
Compiling and executing:
% cc -Wall -Werror -Wextra main.c libftprintf.a
% ./a.out