Skip to content

Apinedas/printf

Repository files navigation

_printf Function:page_facing_up:

The _printf program is a pseudo- recreation of the C standard library function, printf as part of the low-level programming and algorithm track at Holberton School Colombia.

Dependences

Our _printf function was coded on MacOS 10.14.16 Using bash and Ubuntu 20.04 LTS machine, both with gcc version Version 9.3.0

Man page

If you want to install _printf man page source, just copy _printf.3.gzfile to /usr/local/share/man/man3 or /usr/share/man/man3 path.

using this line:

cp [Your _printf.3.gz path] /usr/local/share/man/man3

or

cp [Your _printf.3.gz path] /usr/share/man/man3 

Then, you can type man _printfin your console. and you'll be reading our man page.

Flowchart

Flowchart Template

Usage

To use the _printf function, assuming the above .c dependencies have been installed, compile all .c files in the repository and include the header main.hin the entry point function.

Example main.c:

#include "main.h"

int main()
{
    _printf("Hi buddy,from C16!");

    return (0);
}

Compilation:

$ gcc *.c -o [File_name]

Output:

$ ./[File_Name]
Hi buddy, from C16!
$

Description

Syntaxis

Prototype:

int _printf(const char *format, ...);

The function _printf writes output to standard output.

The function writes under the control of a format string that specifies how consecutive arguments (accessed via the variable-length facilities of stdarg) are converted for output.

Return Value

If successful return, _printf returns the number of characters printed excluding the terminating null byte used to end output to strings.

But If an output error is encountered, the function returns -1 and it does not print anything.

Format of the Argument String

The format string is a constant character string composed of ordinary characters which are copied unchanged to the output stream.

Specification cases are introduced by the character % and ends with a conversion specifier.

Conversion Specifiers

The conversion specifier introduced by the character % is a character that specifies the type of conversion to be applied.

The _printf function supports the following conversion specifiers:

d, i

The i and d argument is converted to char for decimal and integer notation.

Example main.c:

int main()
{
    _printf("%d\n", 9);
}

Output:

9

o, u, x, X

The unsigned int argument is converted to: unsigned octal (o), unsigned decimal (u), unsigned hexadecimal (x) and unsigned hexadecimal Uppercase(X).

The letters abcdef are used for x conversions and the letters ABCDEF are used for X conversions.

Then for each case, modded utoa pseudo functions were used

Example main.c:

int main()
{
    _printf("%o\n", 77);
}

Output:

115

c

The int argument is converted to an char.

Example main.c:

int main()
{
    _printf("%c\n", 48);
}

Output:

0

s

Arguments are printed as a string.

Example main.c:

int main()
{
    _printf("%s\n", "Hello, World!");
}

Output:

Hello, World!

%

A % is written. No argument is converted. The complete conversion specification is %%.

Example:

int main(void)
{
    _printf("%%\n");
}

Output:

%

Reverse String

String arguments are printed in reverse.

Example:

int main(void)
{
	_printf("%r\n", "Hello");
}

Output:

olleH

ROT13

String arguments are coded in ROT13

Example:

int main(void)
{
	_printf("%R\n", "Hello");
}

Output:

Uryyb

Authors

Acknowledgements

This program was written as part of the curriculum for Holberton School. Holberton School is a campus-based full-stack software engineering program that prepares students for careers in the tech industry using project-based peer learning. For more information, visit this link.

This is a secret;)

About

printf project for Holberton School

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages