The Printf project is a customized implementation of the printf function in the C language. The printf function is a standard library function used to display formatted messages on standard output (usually the console).
- Objective
- Compilation command
- Requirements
- Mandatory Tasks
- Specifiers
- Examples and tests
- Man page
- Flowchart
- Installation
- Thanks
- Authors
The objective of this project is to create our own printf function to understand the underlying concepts related to variable arguments and format specifiers in C.
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c
- Allowed editors:
vi
,vim
,emacs
- All files will be compiled on Ubuntu 20.04 LTS
- Code must follow the
Betty
style - Global variables are not allowed
- No more than functions per file
- All prototypes for functions should be included in our header file
main.h
- Authorized functions and macros:
- write (man 2 write)
- malloc (man 3 malloc)
- free (man 3 free)
- va_start (man 3 va_start)
- va_end (man 3 va_end)
- va_copy (man 3 va_copy)
- va_arg (man 3 va_arg)
- Write a function that produces output according to a format and the following conversion specifiers
c
,s
, and%
.
- Handle the following conversion specifiers
d
,i
.
- Create a man page for your function.
_printf supports the following format specifiers:
- %c: prints a single character
- %s: prints a string of characters
- %%: prints a literal '%' character
- %d: prints a decimal number
- %i: signed integer number
My own tests in comparison with the standard printf function(main.c file):
Input
#include <limits.h>
#include <stdio.h>
#include "main.h"
/**
* main - Entry point
*
* Return: Always 0
*/
int main(void)
{
int len;
int len2;
len = _printf("Printf is so much fun!\n");
len2 = printf("Printf is so much fun!\n");
_printf("Length:[%d, %i]\n", len, len);
printf("Length:[%d, %i]\n", len2, len2);
_printf("Negative:[%d]\n", -823405);
printf("Negative:[%d]\n", -823405);
_printf("Character:[%c]\n", 'A');
printf("Character:[%c]\n", 'A');
_printf("String:[%s]\n", "Learning for a lifetime");
printf("String:[%s]\n", "Learning for a lifetime");
len = _printf("Percent:[%%]\n");
len2 = printf("Percent:[%%]\n");
_printf("Len:[%d]\n", len);
printf("Len:[%d]\n", len2);
_printf("Unknown:[%r]\n");
printf("Unknown:[%r]\n");
_printf("Len:[%d]\n", INT_MIN);
printf("Len:[%d]\n", INT_MIN);
return (0);
}
Output
Printf is so much fun!
Printf is so much fun!
Length:[23, 23]
Length:[23, 23]
Negative:[-823405]
Negative:[-823405]
Character:[A]
Character:[A]
String:[Learning for a lifetime]
String:[Learning for a lifetime]
Percent:[%]
Percent:[%]
Len:[12]
Len:[12]
Unknown:[%r]
Unknown:[%r]
Len:[-2147483648]
Len:[-2147483648]
More information with the command: man ./man_3_printf
or on our man page
- Clone this repository on your local machine:
git clone
https://github.com/Julieed-971/holbertonschool-printf.git
- Compile the source files with the following command:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c -o 0-printf
Special thanks to my #C22 peers Rodrigues, and his infinite patience, Yasine, Theo, Nathan, Gilles, Chloe and Elie. Very special thanks to Fabien, Yoann and Xavier, the absolute best tutors that can ever be !
- Github: @Julieed-971
- Github: @SaadiKhemchane