The objective of the printf project is to learn the base functionality of printf, take those concepts and apply them ourselves to create a new printf that works in the same way.
Our printf project has been tested on Ubuntu 14.04 LTS
via Vagrant in VirtualBox.
The repository contains the following files:
File | Description |
---|---|
new_printf.c | Our take on the printf function |
holberton.h | Contains file declarations |
get_function.c | Chooses which function to use based on a specific format modifier |
functions.c | Contains the functions that handle how to print different types |
Function | Description |
---|---|
int _printf(const char *format, ...); | This function returns the number of characters printed, excluding the null byte used to end output to strings. If an output error is encountered, a negative value is returned. |
int _putchar(char c); | Writes a character to stdout . Returns 1 because a character was printed. |
int (*get_func(char c))(va_list list); | Matches the character provided to the appropriate function. Returns NULL if nothing matches. |
int print_char(va_list list); | Writes a character to stdout by retrieving the next argument in va_list . Returns 1 because one character was printed. |
int print_string(va_list list); | Writes one character at a time to stdout . Prints (null) if string is NULL . Returns the number of times it prints a character. |
int print_non(char ch1, char ch2); | Writes non supported format modifiers to stdout . Returns 1 if the character after the format modifier is a % , or returns 2 for anything else. |
int print_num(va_list list); | Prints a number to stdout . Returns the amount of individual numbers and sign printed. |
Start by cloning the repository to a directory, then run the executable.
(hbtn)$ git clone https://github.com/RoMalms10/printf.git
This code was compiled with the following flags:
(hbtn)$ gcc -Wall -Wextra -Werror -pedantic -Wno-format *.c -o print
int main(void)
{
_printf("Print a %s\n", "string");
return (0);
}
=========================================
(hbtn)$ ./print
Print a string
(hbtn)$
Other format modifiers are currently in development.
Increase the amount of commands that are accepted by our rendition of printf:
- Format modifiers:
- r
- R
- x
- X
- u
- o
- S
- p
- Flag characters:
- +
- space
- #
- 0
- -
- Length Modifiers:
- l
- h
- field width for non-custom conversion specifiers