Create a printf function in C
This project is about making a custom prototype of the function printf, emulating the original one.
- In C programming language, printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.
Category | Technology/Tool |
---|---|
Backend |
|
Editors |
|
Utilities |
printf is the C language function to do formatted printing, in the most simple case, printf takes one argument, a string of characters, for example, so it can be displayed on the screen but the real power of printf is when we are printing the contents of variables, basing on the format promted for display such variable. Every format specification starts with a percent sign "%" and ends with a letter. The letters are chosen to have some mnemonic meaning. Here is a partial list:
%c print a single character
%d print a decimal (base 10) number
%e print an exponential floating-point number
%f print a floating-point number
%g print a general-format floating-point number
%i print an integer in base 10
%o print a number in octal (base 8)
%s print a string of characters
%u print an unsigned decimal (base 10) number
%x print a number in hexidecimal (base 16)
%% print a percent sign (\% also works)
Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings).
$ git clone https://github.com/diegozencode/printf.git
#include <stdio.h>
#include "holberton.h"
/**
* main - Entry point
*
* Return: Always 0 (Success)
*/
int main(void)
{
_printf("Hello there!\n");
_printf("String: %s\n", "Hello world!");
return (0);
}
You can compile the files using this command:
$ gcc -Wall -pedantic -Werror Wextra *.c
Create a new branch with the name of your feature or fix and make a pull request to develop branch explaining your work.
- David Bravo - dbravo0
- Diego Monroy (@diegozencode) -
|
|