Skip to content

Patricio-Benglian/holbertonschool-printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

_printf

_printf("{string}", {...})

Table of Contents


Requirements

  • Allowed editors: vi, vim, emacs
  • All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -Werror -Wextra -pedantic -std=gnu89
  • Your code should use the Betty style. It will be checked using betty-style.pl and betty-doc.pl
  • You are not allowed to use global variables
  • No more than 5 functions per file

How it works

The _printf function located in _printf.c allows you to print strings to standard output with flexibility. It can receive conversion specifiers (% followed by specific characters) which will be replaced with strings. The specific character following the % specifies indicates the kind of argument it is recieving.

When this function is used, the program scans and writes every character in the string until a % is found. Once % is found it does one of several things depending on the value of the next character.

If the next character doesn't exist, it doesn't print anything else and returns the function with an error value of -1. If the next character does exist, it calls an auxiliary function which compares the value of the next character with a list of valid characters for conversion specifiers. If it finds a match, it calls the respective auxiliary function to print the recieved argument. (For example, if %s is used in _printf, the structure will check the structure for an 's', and if a match is found, will run the corresponding function (in this case it will use the print_string function.) If no match is found, it prints both the % sign and the subsequent character and continues as normal.

Syntax Output
_printf("String"); String
_printf("%s\n", "Also a string"); Also a string
_printf("%s%c%%", "Hello w", o); Hello wo%

%s

Indicates that the argument received is of type char * (string).

Example:

Syntax Output
_printf("%s", "Hello"); Hello

%c

Indicates that the argument received is of type char.

Syntax Output
_print("%cello", 'H'); Hello

%%

Nullifies previous % character, allowing to print %.

Syntax Output
_printf("%%s%%"); %s%

%i

Indicates that the argument is of type integer.

Syntax Output
_printf("I am %i years old", 23) I am 23 years old

%d

Indicates that the argument is of type decimal. Functionally the same as %i in most cases.

Syntax Output
_printf("It is currently %d O'clock", 12); It is currently 12 O'clock

Authors

Nicolás Fernandez @Nicoou
Patricio Benglian @Patricio-Benglian

Flowcharts

_printf.c flowchart
get_conv.c flowchart
aux_func.c flowcharts
print_char
print_string
print_perc
print_num

About

Printf group project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages