Code Monkey home page Code Monkey logo

ft_printf's People

Contributors

eblackbu avatar reoil avatar

Watchers

 avatar  avatar

ft_printf's Issues

Handle diouxX ๐Ÿ˜ค๐Ÿ˜ค๐Ÿ˜ค

diouxX

Man info

The int (or appropriate variant) argument is converted to signed decimal (d and i), unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal (x and X) notation.

The letters "abcdef'' are used for x conversions; the letters "ABCDEF'' are used for X conversions.

The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded on the left with zeros.

Data type

Conversion Real type C type Out with -1 Out with 0 Out with 1
%d signed decimal int -1 0 1
%i signed decimal int -1 0 1
%o unsigned octal unsigned int 37777777777 0 1
%u unsigned decimal unsigned int 4294967295 0 1
%x unsigned hexadecimal unsigned int ffffffff 0 1
%X unsigned hexadecimal unsigned int FFFFFFFF 0 1

Example:

printf("%d", 1337); // out: 1337
printf("%i", 1337); // out: 1337
printf("%o", 1337); // out: 2471
printf("%u", 1337); // out: 1337
printf("%x", 1337); // out: 539
printf("%X", 1337); // out: 539

Modificator

Man info

Modifier d, i o, u, x, X
hh signed char unsigned char
h short unsigned short
ll long long unsigned long long
l long unsigned long

Example

printf("%hd", 1337); // out: 1337
printf("%hhd", 1337); // out: 57
printf("%ld", 1337); // out: 1337
printf("%lld", 1337); // out: 1337

Handle csp ๐Ÿ˜œ๐Ÿ˜œ

csp

Man info

c The int argument is converted to an unsigned char, and the resulting character is written.

s The char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a terminating NUL character; if a precision is specified, no more than the number specified are written. If a precision is given, no null character need be present; if the precision is not specified, or is greater than the size of the array, the array must contain a terminating NUL character.

p The void * pointer argument is printed in hexadecimal (as if by "%#x" or "%#lx").

Data type

Conversion C type
%c int (conver)-> unsigned char
%s char *
%p void *

Example

printf("%c", 'a'); // out: a
printf("%p", 0x1); // out: 0x1
printf("%s", "abc"); // out: abc

Floating ๐Ÿ˜ฑ๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ˜ญ

Floating ๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ˜ญ

Man info

f The double argument is rounded and converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal point appears, at least one digit appears before it.

Data type

Conversion C type
%f double

Example:

printf("%f", 13.37); // out: 13.370000

Modificator

Man info

Modifier f
l double
L long double

#0-+ and space ๐Ÿ‘€๐Ÿ‘€๐Ÿ‘€

#0-+ and space

Man info

"#"

The value should be converted to an "alternate form''. For c, d, i, n, p, s, and u conversions, this option has no effect. For o conversions, the precision of the number is increased to force the first character of the output string to a zero. For x and X conversions, a non-zero result has the string "0x" (or "0X" for X conversions) prepended to it. For a, A, e, E, f, F, g, and G conversions, the result will always contain a decimal point, even if no digits follow it (normally, a decimal point appears in the results of those conversions only if a digit follows). For g and G conversions, trailing zeros are not removed from the result as they would otherwise be.

"0" (zero)

Zero padding. For all conversions except n, the converted value is padded on the left with zeros rather than blanks. If a precision is given with a numeric conversion (d, i, o, u, i, x, and X), the 0 flag is ignored.

"-"

A negative field width flag; the converted value is to be left adjusted on the field boundary. Except for n conversions, the converted value is padded on the right with blanks, rather than on the left with blanks or zeros. A - overrides a 0 if both are given.

" " (space)

A blank should be left before a positive number produced by a signed conversion (a, A, d, e, E, f, F, g, G, or i).

"+"

A sign must always be placed before a number produced by a signed conversion. A + overrides a space if both are used.

Example

"#"

printf("%#x", 0x1337); // out: 0x1337
printf("%#X", 0x1337); // out: 0X1337
printf("%#X", 0x1337); // out: 0X1337
printf("%#o", 01337); // out: 01337
printf("%#d", 1337); // out: 1337

"+"

printf("%+i", 1); // out: +1
printf("%+i", 0); // out: +0
printf("%+i", -1); // out: -1

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.