Skip to content

Create a custom prototype of the function printf, emulating the original one written in C programming language

Notifications You must be signed in to change notification settings

diegozencode/printf

Repository files navigation

Printf project

Create a printf function in C

Description

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.

Technologies & Tools 💻

Category Technology/Tool
Backend C
Editors Vim GNU Emacs
Utilities Ubuntu Git GNU_Bash Vagrant

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)

Return value

Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings).


Example

Clone repo using HTTPS

$ git clone https://github.com/diegozencode/printf.git

Create main function

#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);
}

Compilation

You can compile the files using this command: $ gcc -Wall -pedantic -Werror Wextra *.c


Contribution

Create a new branch with the name of your feature or fix and make a pull request to develop branch explaining your work.


Authors

  • David Bravo - dbravo0
  • Diego Monroy (@diegozencode) - Twitter - @diegozencode | LinkedIn - Diego Felipe Monroy | Personal Website - diegozencode.com

About

Create a custom prototype of the function printf, emulating the original one written in C programming language

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages