Giter VIP home page Giter VIP logo

42bangkok-ft_printf's Introduction

ft_printf

printft_badge

42cursus' project

The printf function is one of the most versatile and well-known functions in the C language.From a testing aid to tabulation method, printf is a very powerful and important tool in everydev's kit. This project aims to recreate the behaviour of the original MacOS's printf, includingits basic error management, some of its flags, minimum field width stipulation and most of itsbasic conversions.

Features

printft_point

Subject

Write a lib with ft_printf function that will mimic the real printf

Allow Function

malloc(), free(), write(), va_start(), va_arg(), va_copy(), va_end()

Mandatory

A small description of the required conversion:

  • %c print a single character.
  • %s print a string of characters.
  • %p The void * pointer argument is printed in hexadecimal.
  • %d print a decimal (base 10) number.
  • %i print an integer in base 10.
  • %u print an unsigned decimal (base 10) number.
  • %x print a number in hexadecimal (base 16).
  • %% print a percent sign.

Bonus

Manage any combination of the following flags:

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

What is ft_printf?

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

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

ft_printf can print different contents depending on conversions and flags. You can print using the following syntax:

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

min-width depending on cases, will add empty spaces. Precision, depending on cases, will add '0'.

See below what are flags, length modifier and conversions.

Conversions & Flags & Expected Order

Conversion Description Project
c Single ascii character Mandatory
s String of characters NULL terminated Mandatory
p Pointer location converted to hexadecimal value Mandatory
d Decimal number Mandatory
i Integer in decimal base Mandatory
u Unsigned integer in decimal base Mandatory
x Unsigned number printed in lowercase hexadecimal base Mandatory
X Unsigned number printed in uppercase hexadecimal base Mandatory
% The '%' ascii character Mandatory
o Unsigned number printed in octal base Extra
Flag Description Project
- Left align the argument passed Bonus 1
0 Add '0' as a padding character in numeric conversions (single space is default) Bonus 1
. Precision definition, followed by a number Bonus 1
+ Add a plus sign ('+') in the front of positive numeric conversions Bonus 2
' ' Add a single space (' ') in the front of positive numeric conversions Bonus 2
# Add the corresponding prefix in front of x, X and o conversions Bonus 2
* Add a placeholder for numeric values that shall be passed through the variadic arguments Extra
Holder key Prefix and justification flags * Minimum Width * Precision * Conversion
% - , 0 , + , ... 10, 5 , ... ., .10, .5, ... c, d, i, s, ...
* : optional flags and definitions

Usage

You can try our project with the following commands:

First, clone the repository

git clone https://github.com/viruskizz/42bangkok-ft_printf
cd ft_printf
make

Algorithm and Concept

My concept printf is write read character ordering and grab %. write a normal character and coverting placeholder format to write coverted string.

Discovery this sheet to understand more about printf using case.

Implementation


printft_concept

  1. Read character in ordering
  2. Check and set formatter string as t_format
  3. Write a character is not found format
    • write(1, &c, 1)
  4. Convert format to converted string (cstr)
  5. Write cstr with print_str or print_char
  6. Shift read cursur equal format string length
  7. Continue to read next character (to step 1)

Conversion type


Credit

README Inspiration:

42bangkok-ft_printf's People

Contributors

viruskizz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

42bangkok-ft_printf's Issues

Bonus

This test :
Screenshot 2023-09-05 at 13 03 48
Give :
Screenshot 2023-09-05 at 13 05 05

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.