Skip to content

The goal of this project is pretty straightforward. You will recode printf().

Notifications You must be signed in to change notification settings

arzelcm/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42 cursus ft_printf

Because ft_putnbr() and ft_putstr() aren’t enough.

The goal of this project is pretty straightforward. You will recode printf(). You will mainly learn about using a variable number of arguments. How cool is that??

It is actually pretty cool :)

Version: 10

Requirements

The prototype for the function must be:

int ft_printf(const char *, ...);

Mandatory

You have to implement the following conversions:

  • %c Prints a single character.
  • %s Prints a string (as defined by the common C convention).
  • %p The void * pointer argument has to be printed in hexadecimal format.
  • %d Prints a decimal (base 10) number.
  • %i Prints an integer in base 10.
  • %u Prints an unsigned decimal (base 10) number.
  • %x Prints a number in hexadecimal (base 16) lowercase format.
  • %X Prints a number in hexadecimal (base 16) uppercase format.
  • %% Prints a percent sign.

Bonus

  • Manage any combination of the following flags: -0. and the field minimum width under all conversions.
  • Manage all the following flags: # + (Yes, one of them is a space).

Development

Syntax

The syntax for every format specifier is:

%[flags][width][.precision]specifier

Flags

-

Justifies the result to the left within the given field width. So padding will be at the right. Ignored if width is not provided.

By default, result is justified to the right. So padding will be at the left.

Note

This flag is in padding group.


0

Sets padding value to 0.

By default, padding value is a space.

Note

This flag is in padding group.


#

Used with %x or %X specifiers. It adds hexadecimal prefix.

Corner case: if value is 0, no prefix is added.

Note

This flag is in hexadecimal group.


.[int] (precision)

For integer specifiers (%d, %i, %u, %x, %X) it sets the minimum number of digits to be written. The default precision is set to 0. If some [int] is found, then precision is reassigned.

Corner case: A precision of 0 means that no character is written for the value 0.

For %s specifier it is the maximum number of digits to be written.

Max value: 2147483646 (INT_MAX - 1).

Note

This flag is in padding group.


(space)

If no sign is written, it inserts a blank space before the value.

Note

This flag is in sign group.


+

Forces the result to be printed with sign (+ or -).

Note

This flag is in sign group.


width

It defines min printed characters amount. When printed characters are not sufficient to reach its value, padding is added to satisfy this requisite.

Note

This flag is in padding group.

By default, width is auto/inherit.

Max value: 2147483646 (INT_MAX - 1).

Priority groups

hexadecimal

Flag priority
# 0

sign

Flag priority
+ 0
(space) 1

padding

Flag priority
- 0
0 1
.[int] (precision) 2
width 3

References

About

The goal of this project is pretty straightforward. You will recode printf().

Topics

Resources

Stars

Watchers

Forks