Giter Site home page Giter Site logo

m0saan / printf Goto Github PK

View Code? Open in Web Editor NEW
4.0 0.0 0.0 251 KB

PRINTF : Because 'putnbr' and 'putstr' aren’t enough. This is a library that contains ft_printf, a function that will mimic the real printf

Makefile 2.99% C 97.01%
ft-printf c-programming-language algorithms printf stdout

printf's Introduction

ft_printf

Description

This project is part of the curriculum provided by 42born2code School. The project is pretty straight forward. ft_printf replicates the C standard library printf() function.

What you should learn from this project:

  • Write well-structured and good extensible code.
  • You will mainly learn how to use variadic arguments.
  • Unix logic
  • Rigor

Prototype

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

Usage

  • Prints a string to the standard output, according to a given format.
  • Basically it manage the following conversions: cspdiuxX%.
  • It manage any combination of the following flags: ’-0.*’ and minimum field width with all conversions.
  • It will be compared with the real printf
  • All files were created and compiled on MacOs Sierra 10.12 using GCC 4.8.4 with the command gcc -Wall -Werror -Wextra -pedantic *.c
  • Returns the number of characters in the output string on success, -1 otherwise
  • Call it this way: ft_printf("format string", arguments...) where format string can contain conversion specifiers and flags, along with regular characters

Examples

  • ft_printf("Hello, 1337FIL\n") prints "Hello, 1337FIL", followed by a new line
  • ft_printf("%s", "Hello") prints "Hello"
  • ft_printf("This is a number: %d", 1337) prints "This is a number: 1337"

How To Install

  • git clone https://github.com/MoBoustta/printf.git
  • cd printf
  • make
  • make clean
  • create a .c file and call include ft_printf header
  • call ft_printf()
  • gcc libftprintf.a file.c; ./aout

Format Specifiers

A format specifier follows this prototype: %[flags][width][.precision][length]type The following format specifiers are supported:

Supported Types

Type Output
d or i Signed decimal integer
u Unsigned decimal integer
x Unsigned hexadecimal integer (lowercase)
X Unsigned hexadecimal integer (uppercase)
c Single character
s String of characters
p Pointer address
% A % followed by another % character will write a single %

Supported Flags

Flags Description
- Left-justify within the given field width; Right justification is the default.
0 Left-pads the number with zeros (0) instead of spaces when padding is specified (see width sub-specifier).

Supported Width

Width Description
(number) Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
* The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

Supported Precision

Precision Description
.number For integer specifiers (d, i, u, x, X): precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0.
For s: this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered.
If the period is specified without an explicit value for precision, 0 is assumed.
.* The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

Author

printf's People

Contributors

m0saan avatar

Stargazers

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