Giter Club home page Giter Club logo

printf's Introduction

printf()

The printf project is a collaboration between Kingsley Emeka Umunna and Chibuzo Ashiegbu, actual students of Software Engineering at ALX Software Engineering Progromme , were a function named "_printf" imitates the actual "printf" command located in the stdio.h library. It contains some of the basic features and functions found in the manual 3 of "printf".

_printf() is a function that performs formatted output conversion and print data. Its prototype is the following:

int _printf(const char *format, ...)

Where format contains the string that is printed. As _printf() is variadic function, it can receives n arguments that replace by n tags written inside the string.

The format tags prototype is the following:

%[flags][length]specifier

If the program runs successfully, the return value is the amount of chars printed.

Specifier Output
c Character
d or i Signed decimal integer
s String of characters
b Signed binary
o Signed octal
u Unsigned integer
x Unsigned hexadecimal
X Unsigned hexadecimal (uppercase)
p Pointer address
r Reverse string of characters
R ROT13 translation of string
S String with special chars replaced by their ASCII value
% Character
Flags Description Specifiers
+ Prints a plus sign (+) when the argument is a positive number. In other case, prints a minus sign (-). i, d
(space) Prints a blank space if the argument is a positive number i, d
# Prints 0, 0x and 0X for o, x and X specifiers, respectively. It doesn't print anything if the argument is zero o, x, X
Length Description Specifiers
l Prints a long int or unsigned long int i, d, o, u, x and X
h Prints a short int or unsigned short int i, d, o, u, x and X

Examples

  1. Printing the string of chars "Hello,ALX ":

    • Use: _printf("Hello ALX%s.", "ALX");
    • Output: Hello ALX .
  2. Printing an integer number:

    • Use: _printf("10 + 10 is equal to %d.", 20);
    • Output: 10 + 10 is equal to 20.
  3. Printing a binary, octal and hexadecimal:

    • Use: _printf("10 in binary is [%b], in octal is [%o] and in hexadecimal is [%x]", 5, 5, 5);
    • Output: 10 in binary is [1010], in octal is [12] and in hexadecimal is [A]
  4. Printing a string codified in ROT13:

    • Use: _printf("Hello in ROT13 is %R", "Hello");
    • Output: Hello in ROT13 is Urybb

Using flags and length tags:

  1. Printing the string of chars "Hello, ALX ":

    • Use: _printf("2 * 2 = %+d and 5 * -5 = %+i", 4, -25);
    • Output: 2 * 2 = +4 and 5 * -5 = -25
  2. Printing a long integer number and short integer number:

    • Use: _printf("1 million as a long int is %ld, but as a short int is %hd", 1000000, 1000000);
    • Output: 1 million as a long int is 1000000, but as a short int is 16960

File Functions

main.h

printf's People

Contributors

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