Skip to content

jydzip/holbertonschool-printf

Repository files navigation

_printf() - Function C

In this project, we are creating a function called _printf().

This function formats a character string and returns it to the terminal output. When the function completes correctly, it returns the number of characters printed.

It works like the function printf() on the <stdio.h> library.

Requirements

  • Ubuntu 20.04 LTS
  • GCC Language standard gnu89

Way to Install Requirements

Installation gcc

$ sudo apt install build-essential

Installation

$ git clone https://github.com/jydzip/holbertonschool-printf.git
$ cd holbertonschool-printf

Compilation and run

$ gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c -o _printf
$ ./_printf

Format Specifiers

Function name Description Format
_print_char Print a single character %c
_print_string Print a string of characters %s
_print_integer Print an integer %i
_print_perc Print a percentage %%
_print_unsigned_integer Print a unsigned integer %u
_print_binary Print a integer converted to binary %b

Usage/Examples

Exemple of main.c for use _printf()

#include "main.h"

int main() {
    int number = 10;
    int number2 = 105;
    char character = 'A';
    char string[] = "Hello, world!";
    int len;

    len = _printf("Display string : %s\n", string);
    _printf("Length of string displayed : %d\n", len);
    _printf("Display integer : %d\n", number);
    _printf("Display character : %c\n", character);
    _printf("Display percentage : %%\n");
    _printf("Display unsigned int : %u\n", number);
    _printf("Display binary : %b\n", number2);

    return (0);
}

STDOUT:

Display string : Hello, world!
Length of string displayed : 31
Display integer : 10
Display character : A
Display percentage : %
Display unsigned int : 10
Display binary : 1101001

Running Tests

To run tests, use the main.c of the Usage/Examples part.

And run the command:

$ ./main_tests.sh

Flowchart

Flowchart

Authors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •