GithubHelp home page GithubHelp logo

ft_printf's Introduction

ft_printf Build Status

What's ft_printf ?

The goal of this project was to recode the famous printf C function to learn variadic functions and to improve my algorithmic methodology

int printf(const char * (restrict) format, ...);

You can print content of a passed parameter by using the following syntax:

%[flag][min width].[precision][length modifier][conversion specifier]

Features

The following conversions are supported:

s: char *
S: wchar_t *
p: void * (to print address of a pointer)
d / i: int
D: intmax_t
o/O: unsigned int/long int to octal output
u/U: unsigned int/unsigned long int
x/X: unsigned int/long int to hexadecimal output
c: char
C: wchar_t

You can also change input types with the following length modifiers:

h/hh/l/ll/j/z

Use the usual flags:

-       Left justify.
0       Field is padded with 0's instead of blanks.
+       Sign of number always O/P.
blank   Positive values begin with a blank.
#       Various uses:
  %#o        0 prefix inserted.
  %#x        0x prefix added to non-zero values.
  %#X        0X prefix added to non-zero values.

And specify width and precision to adapt your output

Bonus

Colors

Output can be colored with the following tags:

{FG_COLOR}: to specify a foreground color
{BG_COLOR}: for a background color

and replace COLOR by one of the following:

DEFAULT
BLACK
WHITE
LIGHT_GREY
DARK_GREY
(LIGHT_)RED
(LIGHT_)GREEN
(LIGHT_)YELLOW
(LIGHT_)BLUE
(LIGHT_)MAGENTA
(LIGHT_)CYAN

An invalid color specifier will cause it to be skipped

Added conversions

b: int to binary output

Trying it

First, clone the project,

git clone https://github.com/jjaniec/ft_printf
cd ft_printf

then make the project and compile your files with the generated libftprintf.a and by adding

#include "ft_printf.h"

and use it like the real printf function

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.