GithubHelp home page GithubHelp logo

arzelcm / ft_printf Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 46 KB

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

Makefile 6.82% C 93.18%
42barcelona 42born2code c clang printf-42 ft-printf

ft_printf's Introduction

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

ft_printf's People

Contributors

arzelcm avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.