This is a Holberton School project implementing a custom version of the C standard library printf function.
The _printf function produces output according to a format string, similar to the standard printf function. It writes the output to stdout and returns the number of characters printed.
- Allowed editors: vi, vim, emacs
- All files compiled on Ubuntu 20.04 LTS using gcc with flags:
-Wall -Werror -Wextra -pedantic -std=gnu89 - All files end with a newline
- Code follows Betty style guide
- No global variables allowed
- Maximum 5 functions per file
- All function prototypes in
main.h - Header file includes guards
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c -o printfmain.h- Header file with function prototypes and include guards_printf.c- Main implementation file containing the_printffunction and helper functionsman_3_printf- Manual page for the_printffunctionREADME.md- This file
%c- Print a character%s- Print a string%%- Print a percent sign
%d- Print an integer in decimal%i- Print an integer in decimal
- Created man page documentation (
man_3_printf)
int _printf(const char *format, ...);- Number of characters printed (excluding the null byte) on success
- -1 if format is NULL
#include "main.h"
int main(void)
{
_printf("Hello, %s!\n", "World");
_printf("Number: %d\n", 42);
_printf("Character: %c\n", 'A');
_printf("Percent: %%\n");
return (0);
}- This implementation does not handle buffer management like the standard printf
- Flag characters, field width, precision, and length modifiers are not supported
- For unrecognized conversion specifiers, a percent sign followed by the character is printed
- A trailing percent sign at the end of the format string is ignored
Holberton School printf implementation group