Giter Site home page Giter Site logo

vvarodi / ft_printf Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 408 KB

๐Ÿ“ This project is about recoding the famous printf C function to learn variadic functions and improve algorithmic methodology.

Makefile 5.50% C 94.50%
42 42born2code 42projects 42school 42-school printf printf-42 ft-printf ft-printf42 c

ft_printf's Introduction

ft_printf - @42born2code

GitHub repo size GitHub last commit

score

test

Table of Content

What is ft_printf?

Regardless of the programming language considered, the printf function, (or its equivalents) is always highly useful. The main reason is the ease of its formatting, and the support of diverse types in variable numbers. In short, undeniably, printf is a vital function. In this project, we are ask to recode it and add it to our libft so that we can use it in all of our future projects.

The versatility of the printf function in C represents a great exercise in programming for us. It allow us to discover a feature of the C language โ€“ variadic functions โ€“ and to practice detailed management of the printing options.

Features

The prototype of ft_printf should be:

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

External functions allowed: malloc, free, write, va_start, va_arg, va_copy, va_end

It will manage the following conversions: c s p d i u x X %

Conversions:

%                   (% character)
c    char           (character)
s    char *         (string)
p    void *         (pointer's address)
u    unsigned int   (unsigned decimal integer)
x/X: unsigned int   (hexadecimal)
d/i: int            (integer)

My ft_printf will manage any combination of the following flags: -0.* and minimum field width with all conversions.

Placeholders:

%[Flags][Width][.Precision][Length]<type>

Flags:

-       Left alignment. (default rigth aligned)
0       Field is padded with 0's instead of space.
.       Precision
*       The width or precision is not specified in the format string, 
        but as an additional integer value argument (given by the next va_arg)

Width: Minumum number of characters to output (pads if necessary)

Precision: Maximum limit of characters to output (rounds if necessary)

Installation

git clone https://github.com/vvarodi/ft_printf
cd ft_printf
make

Compilation

Then compile your file with the generated libftprintf.a by adding in the main

#include "ft_printf.h"

(You can compare it with the real printf #include <stdio.h>)

gcc main.c libftprintf.a
./a.out

Usage (some examples)

Basic conversions: Basic Basic-output

ft_printf's People

Stargazers

 avatar  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.