reoil / ft_printf Goto Github PK
View Code? Open in Web Editor NEWft_printf
ft_printf
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").
Conversion | C type |
---|---|
%c |
int (conver)-> unsigned char |
%s |
char * |
%p |
void * |
printf("%c", 'a'); // out: a
printf("%p", 0x1); // out: 0x1
printf("%s", "abc"); // out: abc
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.
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.
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.
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
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.
Conversion | C type |
---|---|
%f |
double |
printf("%f", 13.37); // out: 13.370000
Modifier | f |
---|---|
l |
double |
L |
long double |
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.
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 |
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
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 |
printf("%hd", 1337); // out: 1337
printf("%hhd", 1337); // out: 57
printf("%ld", 1337); // out: 1337
printf("%lld", 1337); // out: 1337
% A "%" is written. No argument is converted. The complete conversion specification is "%%"
printf("%%"); //out: %
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.