Skip to content

Printf custom version is a C language function to do formatted printing. Prints formatted text to the standard output (stdout) using format specifiers.

License

Notifications You must be signed in to change notification settings

ralexrivero/printf

Repository files navigation

printf - custom function

version 1.1 [release date:]: # Date: 2020-07-24

                      ███              █████       ██████
                     ░░░              ░░███       ███░░███
 ████████  ████████  ████  ████████   ███████    ░███ ░░░
░░███░░███░░███░░███░░███ ░░███░░███ ░░░███░    ███████
 ░███ ░███ ░███ ░░░  ░███  ░███ ░███   ░███    ░░░███░
 ░███ ░███ ░███      ░███  ░███ ░███   ░███ ███  ░███
 ░███████  █████     █████ ████ █████  ░░█████   █████
 ░███░░░  ░░░░░     ░░░░░ ░░░░ ░░░░░    ░░░░░   ░░░░░
 ░███
 █████
░░░░░

Content

Introduction to the project

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.

Evironment

C programming language C programming language C programming language
  • 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

Specifiers

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

Repository files

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

Install

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 files
  • full: test wide use cases with special output
  • binary: test binary function
  • hexa: test hexadecimal function
  • octal: test octal function
  • reverse: test reverse function
  • rot: test rot function
  • unsigned: test unsigned function
  • char: test char function
  • string: test string function
  • special: test special function
  • fclean: 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

Test folder contain the main failes to test the functions.

Examples

_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]

Manual

To get help about the printf function ask the manual pages on the terminal:

$ man ./man_3_printf

Flowchart


_printf flowchart



About authors

Diego

Ronald

Joaquin

About

Printf custom version is a C language function to do formatted printing. Prints formatted text to the standard output (stdout) using format specifiers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published