version 1.1
[release date:]: # Date: 2020-07-24
███ █████ ██████
░░░ ░░███ ███░░███
████████ ████████ ████ ████████ ███████ ░███ ░░░
░░███░░███░░███░░███░░███ ░░███░░███ ░░░███░ ███████
░███ ░███ ░███ ░░░ ░███ ░███ ░███ ░███ ░░░███░
░███ ░███ ░███ ░███ ░███ ░███ ░███ ███ ░███
░███████ █████ █████ ████ █████ ░░█████ █████
░███░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░
░███
█████
░░░░░
printf()
function is used to print the character, string, float, integer, octal and hexadecimal values to the standard output.
Printf function prints formatted text to the standard output, and returns the number of characters printed. It is a very powerful function, and it is used to print the values of variables, and to print the values of the expressions. The printf function identify the placeholder and return the value passed.
- Language: C
- OS: Ubuntu 20.04 LTS
- Editor: VIM 8.1.2269
- Compiler: gcc 9.3.0
- -Wall -Wextra -Werror -pedantic -std=gnu89 -Wno-format
- Style guidelines: Betty style
Specifier characters at the end define the type and the interpretation of its corresponding argument:
Specifier | Output |
---|---|
c |
character |
s |
string |
% |
% |
d or i |
Signed integer |
R |
Rot translation |
r |
string reverse |
b |
Binary convertion |
o |
octal convertion |
u |
unsigned convertion |
Name | Description |
---|---|
holberton.h |
includes prototypes and structres |
_printf.c |
main function |
p_*.c |
custom function, one per function |
_putchar.c |
emulates the putchar function |
man_3_printf |
man page |
To install execute in terminal the following command:
$ git clone https://github.com/ralexrivero/printf.git
Cloning into 'printf'...
remote: Enumerating objects: 1004, done.
remote: Counting objects: 100% (341/341), done.
remote: Compressing objects: 100% (246/246), done.
remote: Total 1004 (delta 208), reused 212 (delta 95), pack-reused 663
Receiving objects: 100% (1004/1004), 261.72 KiB | 638.00 KiB/s, done.
Resolving deltas: 100% (618/618), done.
To compile execute in terminal the make
command folowing of any of the targets:
all
: compile all filesfull
: test wide use cases with special outputbinary
: test binary functionhexa
: test hexadecimal functionoctal
: test octal functionreverse
: test reverse functionrot
: test rot functionunsigned
: test unsigned functionchar
: test char functionstring
: test string functionspecial
: test special functionfclean
: clean all executable files
Example of use:
$ make all
gcc -Wall -Wextra -Werror -pedantic -std=gnu89 -Wno-format *.c test/main.c -o printf
Execute the program:
$ ./printf
Let's try to printf a simple sentence.
Let's try to printf a simple sentence.
Length:[39, 39]
Length:[39, 39]
Negative:[-762534]
Negative:[-762534]
Unsigned:[2147484671]
Unsigned:[2147484671]
Unsigned octal:[20000001777]
Unsigned octal:[20000001777]
Unsigned hexadecimal:[800003ff, 800003FF]
Unsigned hexadecimal:[800003ff, 800003FF]
Character:[H]
Character:[H]
String:[I am a string !]
String:[I am a string !]
Address:[%p]
Address:[0x7ffe637541f0]
Percent:[%]
Percent:[%]
Len:[12]
Len:[12]
Unknown:[
]FF300008 ,ff300
]0f145736eff
]%
]21[:neL]
Unknown:[%r]
Test folder contain the main failes to test the functions.
_printf functions examples:
_printf("char: [%c]\n", 'H');
char: [H]
printf("string: [%s]\n", "Hello people !");
Output: string: [Hello people !]
_printf("integer: [%i]\n", 26);
Output: integer: [26]
_printf("decimal: [%d]\n", 10000);
Output: decimal: [10000]
_printf("octal [%o]\n", 92);
Output: octal [134]
_printf("Percent: [%%%%]\n");
Output: Percent: [%%]
_printf("Reverse: [%r]\n", "Programming is great!");
Output: Reverse: [!taerg si gnimmargorP]
To get help about the printf function ask the manual pages on the terminal:
$ man ./man_3_printf
Diego
Ronald
Joaquin