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.
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
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.
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.
#include "main.h"
int main()
{
_printf("Hi buddy,from C16!");
return (0);
}
$ gcc *.c -o [File_name]
$ ./[File_Name]
Hi buddy, from C16!
$
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.
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.
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.
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:
The i and d argument is converted to char for decimal and integer notation.
int main()
{
_printf("%d\n", 9);
}
9
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
int main()
{
_printf("%o\n", 77);
}
115
The int argument is converted to an char.
Example main.c:
int main()
{
_printf("%c\n", 48);
}
Output:
0
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:
%
String arguments are printed in reverse.
Example:
int main(void)
{
_printf("%r\n", "Hello");
}
Output:
olleH
String arguments are coded in ROT13
Example:
int main(void)
{
_printf("%R\n", "Hello");
}
Output:
Uryyb
- Andrés Medina <TheRealMedi>
- Alejandro Pineda Sánchez <Apinedas>
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.
