Skip to content

francois0002/holbertonschool-printf

Repository files navigation

Holberton

C - Printf


Duo


Menu:


➤ Description:

The '_printf' function emulates the standard C language function of the same name, responsible for printing formatted strings on screen. It takes as input an initial variable, a character string, and goes through each character one by one, then prints it.

When it encounters a format specifier (e.g. %s or %d), it extracts the corresponding data type from the arguments and prints the contents of the associated variable.

In the case of an undeclared format specifier, such as %T, the _printf function behaves intuitively by printing the specifier as is, preserving the function's flexibility to handle future directives.


➤ Flowchart:

➤ Flowchart ➤


➤ Format types:

Type Output
%c Print argument of character type
%s Print argument of string type
%i Print argument of integer type
%% Prints a single %
%d Print a decimal (base 10) number

➤ Examples:

  • String without type: _printf("Hello!");

    • Output: Hello!
  • Charater : _printf("%c", 'A');

    • Output: A
  • String: _printf("Whatever happens, %s", "we're a duo that rocks!");

    • Output: Whatever happens, we're a duo that rocks!
  • Integer: _printf("%i", "92");

    • Output: 92
  • Decimal: _printf("%d", "2023");

    • Output: 2023
  • %: _printf("Print a single percent sign : %%");

    • Output: Print a single percent sign : %
  • _printf("Hi Adrien, for this %d session, do you think we could have a %c or min of %i %%?", 2023, 'A', 60);

    • Output: Hi Adrien, for this 2023 session, do you think we could have a A or min of 60 %?

➤ Files that make up the _printf:

  • 1_printf.c : Contains the source code for the printf function.

  • 2_replace_specifier.c : Replacing format specifiers in source code. Format specifiers, such as %s or %d.

  • 3_print_functions.c : Print different types of data.

  • main.h : Header file containing prototypes of functions used in source code. It is included in the rest of the files via the expression: #include "main.h".

  • _putchar.c: Writes the character c to stdout.

  • flowchart.jpeg: Graphical representation of printf.

  • LICENSE: MIT license.

  • man_3_printf: Manuel printf.

  • README.md: Docs.

  • Compile the code using : gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c

  • Read the man using : man ./man_3_printf


➤ Requirements:

General

  • Files can be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -Werror -Wextra -pedantic -std=gnu89.
  • A README.md file is bring at the root of the folder of the project.
  • Our code use the Betty style.
  • There is no use global variables.
  • There is no more than 5 functions per file.
  • You can use your own main.c files at compilation.
  • If you want add some functions, you can put the prototypes in the header file called main.h.

➤ Author:


➤ License:

This project is subject to the MIT license. For detailed information on the conditions of this license, please consult the "LICENSE" file included in the project.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages