A custom implementation of the standard C library printf function. This project demonstrates understanding of variadic functions, format specifiers, and low-level I/O operations in C.
| Specifier | Description |
|---|---|
c |
Single character |
s |
String (prints "(null)" for NULL) |
d, i |
Signed decimal integer |
u |
Unsigned decimal integer |
b |
Binary representation |
o |
Octal representation |
x |
Lowercase hexadecimal |
X |
Uppercase hexadecimal |
%% |
Percent sign |
#include "main.h"
int main(void)
{
_printf("Character: %c\n", 'A');
_printf("String: %s\n", "Hello, World!");
_printf("Integer: %d\n", 42);
_printf("Unsigned: %u\n", 255);
_printf("Binary: %b\n", 10);
_printf("Octal: %o\n", 64);
_printf("Hex lowercase: %x\n", 255);
_printf("Hex uppercase: %X\n", 255);
_printf("Percent: %%\n");
return (0);
}Returns the number of characters printed (excluding the null byte used to end output to strings).
.
├── _printf.c # Main printf function implementation
├── _putchar.c # Character output function
├── _strlen.c # String length calculation
├── get_specifier.c # Format specifier handler
├── print_binary.c # Binary format printing
├── print_char.c # Character format printing
├── print_hex.c # Lowercase hexadecimal printing
├── print_HEXA.c # Uppercase hexadecimal printing
├── print_int.c # Integer format printing
├── print_octal.c # Octal format printing
├── print_string.c # String format printing
├── print_unsigned.c # Unsigned integer printing
├── main.h # Header file with prototypes and definitions
└── README.md # This file
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o _printfint _printf(const char *format, ...);
int (*get_specifier(char s))(va_list);
int print_char(va_list args);
int print_string(va_list args);
int print_int(va_list args);
int print_binary(va_list args);
int print_unsigned(va_list args);
int print_octal(va_list args);
int print_hex(va_list args);
int print_HEX(va_list args);
int _putchar(char c);
int _strlen(char *s);- Uses
va_listfor handling variable arguments - Employs function pointers for format specifier handling
- Uses
write()system call for low-level character output - No external dependencies beyond standard C libraries