conversion works
This commit is contained in:
3
Makefile
3
Makefile
@@ -17,7 +17,8 @@ LIBS = $(_LIBS:lib%.a=%)
|
|||||||
SRCS = ft_printf.c \
|
SRCS = ft_printf.c \
|
||||||
ft_next_word.c \
|
ft_next_word.c \
|
||||||
aside.c \
|
aside.c \
|
||||||
ft_convert.c
|
ft_convert.c \
|
||||||
|
main.c
|
||||||
|
|
||||||
ODIR = ./builds
|
ODIR = ./builds
|
||||||
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
|||||||
278
ft_printf.c
278
ft_printf.c
@@ -102,281 +102,3 @@ char *ft_flag_transform(char *s, char *print)
|
|||||||
// print = ft_alternate_form(print) //
|
// print = ft_alternate_form(print) //
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ft_printf_test(char *string, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, string);
|
|
||||||
printf("%s", string);
|
|
||||||
while (*string != '\0')
|
|
||||||
{
|
|
||||||
printf(" : ");
|
|
||||||
if (*string == 'd')
|
|
||||||
printf("%d", (int)va_arg(ap, long int));
|
|
||||||
if (*string == 'i')
|
|
||||||
printf("%i", (int)va_arg(ap, long int));
|
|
||||||
if (*string == 'u')
|
|
||||||
printf("%u", (unsigned int)va_arg(ap, int));
|
|
||||||
if (*string == 'x')
|
|
||||||
printf("%x", (unsigned int)va_arg(ap, long int));
|
|
||||||
if (*string == 'X')
|
|
||||||
printf("%X", (unsigned int)va_arg(ap, long int));
|
|
||||||
if (*string == 'c')
|
|
||||||
printf("%c", (char)va_arg(ap, long int)); // var_arg promote char into int
|
|
||||||
if (*string == 's')
|
|
||||||
printf("%s", (char *)va_arg(ap, long int));
|
|
||||||
if (*string == 'e')
|
|
||||||
printf("%e", va_arg(ap, double)); // va_arg promote float into double
|
|
||||||
if (*string == 'f')
|
|
||||||
printf("%f", va_arg(ap, double)); // va_arg promote float into double
|
|
||||||
if (*string == 'g')
|
|
||||||
printf("%g", va_arg(ap, double)); // va_arg promote float into double
|
|
||||||
if (*string == 'I')
|
|
||||||
printf("%li", (long int)va_arg(ap, long int));
|
|
||||||
if (*string == 'U')
|
|
||||||
printf("%lu", (unsigned long int)va_arg(ap, long int));
|
|
||||||
string++;
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
va_end(ap);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
char *str = "diuxXcsefg";
|
|
||||||
int d = 123;
|
|
||||||
int i = 456;
|
|
||||||
unsigned int u = 345;
|
|
||||||
unsigned int x = 456;
|
|
||||||
unsigned int X = 567;
|
|
||||||
char c = 'c';
|
|
||||||
char* s = "string";
|
|
||||||
// p = ;
|
|
||||||
float e = 678;
|
|
||||||
float f = 789;
|
|
||||||
float g = 890;
|
|
||||||
// n = ;
|
|
||||||
char *str2 = "iiIIuU";
|
|
||||||
int i1 = 2147483647;
|
|
||||||
int i2 = -2147483648;
|
|
||||||
long int i3 = 9223372036854775807;
|
|
||||||
long int i4 = -9223372036854775807;
|
|
||||||
unsigned int i5 = 4294967295;
|
|
||||||
// long unsigned int i6 = 18446744073709551615;
|
|
||||||
long unsigned int i6 = 8446744073709551615;
|
|
||||||
|
|
||||||
if (ac == 1)
|
|
||||||
{
|
|
||||||
// printf("%s : %d : %i : %u : %x : %X : %c : %s : %e : %f : %g\n", str, d, i, u, x, X, c, s, e, f, g);
|
|
||||||
// ft_printf_test(str, d, i, u, x, X, c, s, e, f, g);
|
|
||||||
// printf("%s : %i : %i : %li : %li : %u : %lu\n", str2, i1, i2, i3, i4, i5, i6);
|
|
||||||
// ft_printf_test(str2, i1, i2, i3, i4, i5, i6);
|
|
||||||
|
|
||||||
printf("sdf\n");
|
|
||||||
ft_printf("sdf\n\n");
|
|
||||||
printf("%i\n", 23);
|
|
||||||
ft_printf("%i\n\n", 23);
|
|
||||||
long int k = -23;
|
|
||||||
printf("%li\n", k);
|
|
||||||
ft_printf("%li\n\n", k);
|
|
||||||
printf("%i\n", -32);
|
|
||||||
ft_printf("%i\n\n", -32);
|
|
||||||
printf("%li\n", 9223372036854775807);
|
|
||||||
ft_printf("%li\n\n", 9223372036854775807);
|
|
||||||
printf("%c\n", 'f');
|
|
||||||
ft_printf("%c\n\n", 'f');
|
|
||||||
printf("%s\n", "sdffhk");
|
|
||||||
ft_printf("%s\n\n", "sdffhk");
|
|
||||||
printf("%u\n", 1221879);
|
|
||||||
ft_printf("%u\n\n", 1221879);
|
|
||||||
printf("%x\n", 3287);
|
|
||||||
ft_printf("%x\n\n", 3287);
|
|
||||||
printf("%lX\n", 9223372036854775807);
|
|
||||||
ft_printf("%lX\n\n", 9223372036854775807);
|
|
||||||
printf("%p\n", "dfgdf");
|
|
||||||
ft_printf("%p\n\n", "dfgdf");
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
conversions : cspdiuxX%
|
|
||||||
flags : - 0 . *
|
|
||||||
conversions : nfge
|
|
||||||
flags : l ll h hh # ' (space) +
|
|
||||||
|
|
||||||
%[arg_nbr$][flags 0,-,#,', ,+][width *][.precision *][length hh,h,ll,l,L,j,t,z][specifier d,i,u,x,X,c,s,p,%,e,f,g,n,E,F,G,a,A,C,S,o]
|
|
||||||
% [flags 0,- ][width *][.precision *] [specifier d,i,u,x,X,c,s,p,% ]
|
|
||||||
% [flags #,', ,+] [length hh,h,ll,l ][specifier e,f,g,n ]
|
|
||||||
|
|
||||||
|
|
||||||
[flags]
|
|
||||||
- left-justify within the given field width
|
|
||||||
0 left-pads the number with zeroes (0) instead of spaces, where
|
|
||||||
padding is specified (see width sub-specifier)
|
|
||||||
( + forces to precede the result with a plus or minus sign even for
|
|
||||||
positive numbers)
|
|
||||||
( (space) if no sign is going to be written, a blank space is inserted
|
|
||||||
before the value)
|
|
||||||
( # (o, x, X, a, A, e, E, f, F, g, G) used with (o, x or X) the
|
|
||||||
value is preceded with 0, 0x or 0X for values different than
|
|
||||||
zero. used with (e, E or f), it forces the written output to
|
|
||||||
contain a decimal point even if no digits would follow. by
|
|
||||||
default, if no digits follow, no decimal point is written. used
|
|
||||||
with (g or G) the result is the same as with e or E but trailing
|
|
||||||
zeros are not removed
|
|
||||||
( ' (d, u, i, f, F) used with d, u or i, or the integral portion of
|
|
||||||
a float f or F, the decimal conversions are printed by groups of
|
|
||||||
thousands separated by the non-monetary separator returned by
|
|
||||||
localeconv(3) (ex 123456789 -> 123,456,789)
|
|
||||||
|
|
||||||
[width]
|
|
||||||
(nbr) 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
|
|
||||||
|
|
||||||
[.precision]
|
|
||||||
.nbr fot integer specifiers (d,i,o,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 e, E and f specifiers − this is the number of
|
|
||||||
digits to be printed after the decimal point. For g and G
|
|
||||||
specifiers − This is the maximum number of significant digits
|
|
||||||
to be printed. 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. For c type − it has no
|
|
||||||
effect. When no precision is specified, the default is 1. 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 formated
|
|
||||||
|
|
||||||
[specifiers]
|
|
||||||
c char character
|
|
||||||
s *char string of characters
|
|
||||||
p * pointer adress
|
|
||||||
d int (or i) signed decimal integer
|
|
||||||
i int (or d) signed decimal integer
|
|
||||||
u u int unsigned decimal integer
|
|
||||||
x u int unsigned hexadecimal integer
|
|
||||||
X u int unsigned hexadecimal integer (capital letters)
|
|
||||||
( n *int nothing printed
|
|
||||||
( f float decimal floating point
|
|
||||||
( e float scientific notation (mantissa/exponent) using e
|
|
||||||
( g float uses the shorter of %e or %f
|
|
||||||
((F float
|
|
||||||
((E float scientific notation (mantissa/exponent) using E
|
|
||||||
((G float uses the shorter of %E or %f
|
|
||||||
((o int signed octal
|
|
||||||
((C char treated as c with l modifier
|
|
||||||
((a float
|
|
||||||
((A float
|
|
||||||
((S *char treated as s with l modifier
|
|
||||||
|
|
||||||
|
|
||||||
p == long unsigned int
|
|
||||||
|
|
||||||
char 1bytes 8bits
|
|
||||||
short 2bytes 16bits
|
|
||||||
int 4bytes 32bits
|
|
||||||
long 8bytes 64bits
|
|
||||||
long long 8bytes 64bits
|
|
||||||
|
|
||||||
255 -127 - +127 00 [char] [hhd, hhi, c] [int] [d( , h, hh), i( , h, hh), c]
|
|
||||||
65535 -32768 - +32767 01 [short] [hd, hi] [int]
|
|
||||||
4294967295 -2147483648 - +2147483647 02 [int] [d, i] [int]
|
|
||||||
18446744073709551615 -9223372036854775808 - +9223372036854775807 04 [long] [ld, li] [long] [d(l ,ll), i(l, ll)]
|
|
||||||
18446744073709551615 -9223372036854775808 - +9223372036854775807 04 [long long] [lld, lli] [long]
|
|
||||||
256 0 - +255 05 [unsigned char] [hhu, hhx, hhX] [unsigned int] [u( , h, hh), x( , h, hh), X( , h, hh), p]
|
|
||||||
65536 0 - +65536 06 [unsigned short] [hu, hx, hX] [unsigned int]
|
|
||||||
4294967296 0 - +4294967296 07 [unsigned int] [u, x, X, p] [unsigned int]
|
|
||||||
18446744073709551616 0 - +18446744073709551616 09 [unsigned long] [lu, lx, lX] [unsigned long] [s, u(l, ll), x(l, ll), X(l, ll)]
|
|
||||||
18446744073709551616 0 - +18446744073709551616 09 [unsigned long long] [llu, llx, llX] [unsigned long]
|
|
||||||
18446744073709551616 0 - +18446744073709551616 10 [char *] [s, hhn] [unsigned long]
|
|
||||||
|
|
||||||
18446744073709551616 0 - +18446744073709551616 16 [double] [e, le, f, lf, g, lg] []
|
|
||||||
18446744073709551616 0 - +18446744073709551616 17 [wint_t] [lc] []
|
|
||||||
18446744073709551616 0 - +18446744073709551616 18 [wchar_t] [ls] []
|
|
||||||
18446744073709551616 0 - +18446744073709551616 11 [short *] [hn] []
|
|
||||||
18446744073709551616 0 - +18446744073709551616 12 [int *] [n] []
|
|
||||||
18446744073709551616 0 - +18446744073709551616 13 [long *] [ln] []
|
|
||||||
18446744073709551616 0 - +18446744073709551616 14 [long long *] [lln] []
|
|
||||||
|
|
||||||
d int 0 int
|
|
||||||
dhh char 1 char
|
|
||||||
dh short 2 short
|
|
||||||
dl long 3 long
|
|
||||||
dll long long 4 long long
|
|
||||||
|
|
||||||
i int
|
|
||||||
ihh char
|
|
||||||
ih short
|
|
||||||
il long
|
|
||||||
ill long long
|
|
||||||
|
|
||||||
u unsigned int 5 unsigned int
|
|
||||||
uhh unsigned char 6 unsigned char
|
|
||||||
uh unsigned short 7 unsigned short
|
|
||||||
ul unsigned long 8 unsigned long
|
|
||||||
ull unsigned long long 9 unsigned long long
|
|
||||||
|
|
||||||
x unsigned int
|
|
||||||
xhh unsigned char
|
|
||||||
xh unsigned short
|
|
||||||
xl unsigned long
|
|
||||||
xll unsigned long long
|
|
||||||
|
|
||||||
X unsigned int
|
|
||||||
Xhh unsigned char
|
|
||||||
Xh unsigned short
|
|
||||||
Xl unsigned long
|
|
||||||
Xll unsigned long long
|
|
||||||
|
|
||||||
c char -> int
|
|
||||||
cl wint_t 10 wint_t
|
|
||||||
s char * 11 char *
|
|
||||||
sl wchar_t * 12 wchar_t *
|
|
||||||
p unsigned int
|
|
||||||
e double 13 double
|
|
||||||
el
|
|
||||||
f double
|
|
||||||
fl
|
|
||||||
g double
|
|
||||||
gl
|
|
||||||
|
|
||||||
n int * 14 int *
|
|
||||||
nhh char *
|
|
||||||
nh short * 15 short *
|
|
||||||
nl long * 16 long *
|
|
||||||
nll long long * 17 long long *
|
|
||||||
|
|
||||||
|
|
||||||
printf("char %lu\n", sizeof(char));
|
|
||||||
printf("short %lu\n", sizeof(short));
|
|
||||||
printf("int %lu\n", sizeof(int));
|
|
||||||
printf("long %lu\n", sizeof(long));
|
|
||||||
printf("long long %lu\n", sizeof(long long));
|
|
||||||
printf("unsigned char %lu\n", sizeof(unsigned char));
|
|
||||||
printf("unsigned short %lu\n", sizeof(unsigned short));
|
|
||||||
printf("unsigned int %lu\n", sizeof(unsigned int));
|
|
||||||
printf("unsigned long %lu\n", sizeof(unsigned long));
|
|
||||||
printf("unsigned long long %lu\n", sizeof(unsigned long long));
|
|
||||||
printf("char * %lu\n", sizeof(char *));
|
|
||||||
printf("short * %lu\n", sizeof(short *));
|
|
||||||
printf("int * %lu\n", sizeof(int *));
|
|
||||||
printf("long * %lu\n", sizeof(long *));
|
|
||||||
printf("long long * %lu\n", sizeof(long long *));
|
|
||||||
printf("double %lu\n", sizeof(double));
|
|
||||||
// printf("wint_t %lu\n", sizeof(wint_t));
|
|
||||||
// printf("wchar_T %lu\n", sizeof(wchar_t));
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|||||||
532
main.c
532
main.c
@@ -2,7 +2,121 @@
|
|||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
int main(void)
|
int ft_printf_test(char *string, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, string);
|
||||||
|
printf("%s", string);
|
||||||
|
while (*string != '\0')
|
||||||
|
{
|
||||||
|
printf(" : ");
|
||||||
|
if (*string == 'd')
|
||||||
|
printf("%d", (int)va_arg(ap, long int));
|
||||||
|
if (*string == 'i')
|
||||||
|
printf("%i", (int)va_arg(ap, long int));
|
||||||
|
if (*string == 'u')
|
||||||
|
printf("%u", (unsigned int)va_arg(ap, int));
|
||||||
|
if (*string == 'x')
|
||||||
|
printf("%x", (unsigned int)va_arg(ap, long int));
|
||||||
|
if (*string == 'X')
|
||||||
|
printf("%X", (unsigned int)va_arg(ap, long int));
|
||||||
|
if (*string == 'c')
|
||||||
|
printf("%c", (char)va_arg(ap, long int)); // var_arg promote char into int
|
||||||
|
if (*string == 's')
|
||||||
|
printf("%s", (char *)va_arg(ap, long int));
|
||||||
|
if (*string == 'e')
|
||||||
|
printf("%e", va_arg(ap, double)); // va_arg promote float into double
|
||||||
|
if (*string == 'f')
|
||||||
|
printf("%f", va_arg(ap, double)); // va_arg promote float into double
|
||||||
|
if (*string == 'g')
|
||||||
|
printf("%g", va_arg(ap, double)); // va_arg promote float into double
|
||||||
|
if (*string == 'I')
|
||||||
|
printf("%li", (long int)va_arg(ap, long int));
|
||||||
|
if (*string == 'U')
|
||||||
|
printf("%lu", (unsigned long int)va_arg(ap, long int));
|
||||||
|
string++;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
va_end(ap);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
/* PREMISES TESTS WITH AV_ARG BASED ON MAN EXEMPLE */
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
|
if (ac == 2 && !strcmp(av[1], "man"))
|
||||||
|
{
|
||||||
|
char *str = "diuxXcsefg";
|
||||||
|
int d = 123;
|
||||||
|
int i = 456;
|
||||||
|
unsigned int u = 345;
|
||||||
|
unsigned int x = 456;
|
||||||
|
unsigned int X = 567;
|
||||||
|
char c = 'c';
|
||||||
|
char* s = "string";
|
||||||
|
// p = ;
|
||||||
|
float e = 678;
|
||||||
|
float f = 789;
|
||||||
|
float g = 890;
|
||||||
|
// n = ;
|
||||||
|
char *str2 = "iiIIuU";
|
||||||
|
int i1 = 2147483647;
|
||||||
|
int i2 = -2147483648;
|
||||||
|
long int i3 = 9223372036854775807;
|
||||||
|
long int i4 = -9223372036854775807;
|
||||||
|
unsigned int i5 = 4294967295;
|
||||||
|
//long unsigned int i6 = 18446744073709551615;
|
||||||
|
long unsigned int i6 = 8446744073709551615;
|
||||||
|
|
||||||
|
// test one of each specifiers
|
||||||
|
printf("%s : %d : %i : %u : %x : %X : %c : %s : %e : %f : %g\n", str, d, i, u, x, X, c, s, e, f, g);
|
||||||
|
ft_printf_test(str, d, i, u, x, X, c, s, e, f, g);
|
||||||
|
// test all different size of int types
|
||||||
|
printf("%s : %i : %i : %li : %li : %u : %lu\n", str2, i1, i2, i3, i4, i5, i6);
|
||||||
|
ft_printf_test(str2, i1, i2, i3, i4, i5, i6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
/* TESTS WHILE BUILDING THE PROGRAM */
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
|
if (ac == 2 && !strcmp(av[1], "test"))
|
||||||
|
{
|
||||||
|
printf("sdf\n");
|
||||||
|
ft_printf("sdf\n\n");
|
||||||
|
printf("%i\n", 23);
|
||||||
|
ft_printf("%i\n\n", 23);
|
||||||
|
long int k = -23;
|
||||||
|
printf("%li\n", k);
|
||||||
|
ft_printf("%li\n\n", k);
|
||||||
|
printf("%i\n", -32);
|
||||||
|
ft_printf("%i\n\n", -32);
|
||||||
|
printf("%li\n", 9223372036854775807);
|
||||||
|
ft_printf("%li\n\n", 9223372036854775807);
|
||||||
|
printf("%c\n", 'f');
|
||||||
|
ft_printf("%c\n\n", 'f');
|
||||||
|
printf("%s\n", "sdffhk");
|
||||||
|
ft_printf("%s\n\n", "sdffhk");
|
||||||
|
printf("%u\n", 1221879);
|
||||||
|
ft_printf("%u\n\n", 1221879);
|
||||||
|
printf("%x\n", 3287);
|
||||||
|
ft_printf("%x\n\n", 3287);
|
||||||
|
printf("%lX\n", 9223372036854775807);
|
||||||
|
ft_printf("%lX\n\n", 9223372036854775807);
|
||||||
|
printf("%p\n", "dfgdf");
|
||||||
|
ft_printf("%p\n\n", "dfgdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
/* COMPLETE TESTS SERIES */
|
||||||
|
/* 557gj */
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
|
if (ac == 2 && !strcmp(av[1], "all"))
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
char c;
|
char c;
|
||||||
@@ -553,170 +667,266 @@ int main(void)
|
|||||||
|
|
||||||
// printf("(\"%%-0i\", 33 : "); ft_printf("'%-+i'\n", 33);
|
// printf("(\"%%-0i\", 33 : "); ft_printf("'%-+i'\n", 33);
|
||||||
printf("(\"%%-0i\", 33 : ");/* printf("'%-0i'\n", 33);*/ printf(" flag '0' is ignored when '-' is present\n\n");
|
printf("(\"%%-0i\", 33 : ");/* printf("'%-0i'\n", 33);*/ printf(" flag '0' is ignored when '-' is present\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
/* 557gk */
|
||||||
|
/* ////////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int flag: pw+ '#-0
|
** conversions : cspdiuxX%
|
||||||
00000000 00000000 00000000 00000001 == 1 '0'
|
** flags : - 0 . *
|
||||||
00000000 00000000 00000000 00000010 == 2 '-'
|
** conversions : nfge
|
||||||
00000000 00000000 00000000 00000100 == 4 '#'
|
** flags : l ll h hh # ' (space) +
|
||||||
00000000 00000000 00000000 00001000 == 8 '''
|
**
|
||||||
00000000 00000000 00000000 00010000 == 16 ' '
|
** %[arg_nbr$][flags 0,-,#,', ,+][width *][.precision *][length hh,h,ll,l,L,j,t,z][specifier d,i,u,x,X,c,s,p,%,e,f,g,n,E,F,G,a,A,C,S,o]
|
||||||
00000000 00000000 00000000 00100000 == 32 '+'
|
** % [flags 0,- ][width *][.precision *] [specifier d,i,u,x,X,c,s,p,% ]
|
||||||
00000000 00000000 00000000 01000000 == 64 '*' width
|
** % [flags #,', ,+] [length hh,h,ll,l ][specifier e,f,g,n ]
|
||||||
00000000 00000000 00000000 10000000 == 128 '*' precision
|
**
|
||||||
|
**
|
||||||
typedef struct s_prist
|
** [flags]
|
||||||
{
|
** - left-justify within the given field width
|
||||||
char *str;
|
** 0 left-pads the number with zeroes (0) instead of spaces, where
|
||||||
int flag; // default 0 ; [0-#' +**] binary
|
** padding is specified (see width sub-specifier)
|
||||||
int width; // default 0 ;
|
** ( + forces to precede the result with a plus or minus sign even for
|
||||||
int prec; // default 0 ; precision
|
** positive numbers)
|
||||||
char *length; // default "\0" ;
|
** ( (space) if no sign is going to be written, a blank space is inserted
|
||||||
char spec; // default 0 ; specifier
|
** before the value)
|
||||||
char *arg; // default "\0" ;
|
** ( # (o, x, X, a, A, e, E, f, F, g, G) used with (o, x or X) the
|
||||||
int p_nb; // default 0 ; print_nb : order in which to print (order it was found in string)
|
** value is preceded with 0, 0x or 0X for values different than
|
||||||
int a_nb; // default 0 ; arg_nb : number of the corresponding argument (for flag $)
|
** zero. used with (e, E or f), it forces the written output to
|
||||||
struct s_prist *next;
|
** contain a decimal point even if no digits would follow. by
|
||||||
} t_prist;
|
** default, if no digits follow, no decimal point is written. used
|
||||||
|
** with (g or G) the result is the same as with e or E but trailing
|
||||||
("2 1 3 4 3", 1, 2, 3, 4)
|
** zeros are not removed
|
||||||
|
** ( ' (d, u, i, f, F) used with d, u or i, or the integral portion of
|
||||||
ft_error(int err)
|
** a float f or F, the decimal conversions are printed by groups of
|
||||||
ft_store("%i truc %-10d machin\n")
|
** thousands separated by the non-monetary separator returned by
|
||||||
ft_split_print(str)
|
** localeconv(3) (ex 123456789 -> 123,456,789)
|
||||||
prist->str = "%i";
|
**
|
||||||
ft_fill_lst(prist)
|
** [width]
|
||||||
prist->flag; // default = 0
|
** (nbr) minimum number of characters to be printed. if the value to be
|
||||||
prist->width; // default = 0
|
** printed is shorter than this number, the result is padded with
|
||||||
prist->prec; // default = 0
|
** blank spaces. The value is not truncated even if the result is
|
||||||
prist->length;
|
** larger
|
||||||
prist->spec;
|
** * the width is not specified in the format string, but as an
|
||||||
prist->p_nb;
|
** additional integer value argument preceding the argument that
|
||||||
prist->a_nb; // if not $ == p_nb
|
** has to be formatted
|
||||||
prist->str = " truc ";
|
**
|
||||||
ft_fill_lst(prist)
|
** [.precision]
|
||||||
... // if str start without % it means it can be printed as a string directly
|
** .nbr fot integer specifiers (d,i,o,x,X) - precision specifies the
|
||||||
prist->str = "%-10d";
|
** minimum number of digits to be written. If the value to be
|
||||||
ft_fill_lst...
|
** written is shorter than this number, the result is padded with
|
||||||
prist->str = " machin\n";
|
** leading zeros. The value is not truncated even if the result is
|
||||||
ft_fill_lst...
|
** longer. A precision of 0 means that no character is written for
|
||||||
return
|
** the value 0. For e, E and f specifiers − this is the number of
|
||||||
{{str; flag; width; precision; length; specifier; p_nb 1; a_nb 2},
|
** digits to be printed after the decimal point. For g and G
|
||||||
{str; flag; width; precision; length; specifier; p_nb 2; a_nb 1},
|
** specifiers − This is the maximum number of significant digits
|
||||||
{str; flag; width; precision; length; specifier; p_nb 3; a_nb 3},
|
** to be printed. For s − this is the maximum number of characters
|
||||||
{str; flag; width; precision; length; specifier; p_nb 4; a_nb 4},
|
** to be printed. By default all characters are printed until the
|
||||||
{str; flag; width; precision; length; specifier; p_nb 5; a_nb 3}}
|
** ending null character is encountered. For c type − it has no
|
||||||
|
** effect. When no precision is specified, the default is 1. If the
|
||||||
ft_sort_by_arg
|
** period is specified without an explicit value for precision, 0
|
||||||
{{str; flag; width; precision; length; specifier; p_nb 2; a_nb 1},
|
** is assumed
|
||||||
{str; flag; width; precision; length; specifier; p_nb 1; a_nb 2},
|
** .* the precision is not specified in the format string, but as an
|
||||||
{str; flag; width; precision; length; specifier; p_nb 3; a_nb 3},
|
** additional integer value argument preceding the argument that
|
||||||
{str; flag; width; precision; length; specifier; p_nb 5; a_nb 3},
|
** has to be formated
|
||||||
{str; flag; width; precision; length; specifier; p_nb 4; a_nb 4}}
|
**
|
||||||
|
** [specifiers]
|
||||||
ft_add_arg
|
** c char character
|
||||||
if lst->str[o] != '\%' rerun without looking for argument
|
** s *char string of characters
|
||||||
if lst->flag == * rerun for next argument but same list element
|
** p * pointer adress
|
||||||
[fl][w][p] or or
|
** d int (or i) signed decimal integer
|
||||||
%i ,1 -> '1' [] [0][0] [ ][0][0] [] [0][0]
|
** i int (or d) signed decimal integer
|
||||||
%*i ,3,1 -> ' 1' [*] [0][0] [* ][0][0] [w] [0][0]
|
** u u int unsigned decimal integer
|
||||||
%.*i ,2,1 -> '01' [*] [0][0] [ *][0][0] [p] [0][0]
|
** x u int unsigned hexadecimal integer
|
||||||
%*.*i ,3,2,1 -> ' 01' [**][0][0] [**][0][0] [wp][0][0]
|
** X u int unsigned hexadecimal integer (capital letters)
|
||||||
%3.*i ,2,1 -> ' 01' [*] [3][0] [ *][3][0] [p] [3][0]
|
** ( n *int nothing printed
|
||||||
%*.2i ,3,1 -> ' 01' [*] [0][2] [* ][0][2] [w] [0][2]
|
** ( f float decimal floating point
|
||||||
%3.2i ,1 -> ' 01' [] [3][2] [ ][3][2] [] [3][2]
|
** ( e float scientific notation (mantissa/exponent) using e
|
||||||
if lst->next->a_nb == lst->a_nb rerun for next list element but same argument
|
** ( g float uses the shorter of %e or %f
|
||||||
{{str; flag; width; precision; length; specifier; arg; p_nb 2; a_nb 1},
|
** ((F float
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 1; a_nb 2},
|
** ((E float scientific notation (mantissa/exponent) using E
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 3; a_nb 3},
|
** ((G float uses the shorter of %E or %f
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 5; a_nb 3},
|
** ((o int signed octal
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 4; a_nb 4}}
|
** ((C char treated as c with l modifier
|
||||||
|
** ((a float
|
||||||
conversions : cspdiuxX%
|
** ((A float
|
||||||
flags : -,0,.,*
|
** ((S *char treated as s with l modifier
|
||||||
conversions : nfge
|
**
|
||||||
flags : l,ll,h,hh,#,', ,+
|
**
|
||||||
|
** p == long unsigned int
|
||||||
usage :
|
**
|
||||||
printf %[arg_nbr$][flags #,0,-, ,+,'][width *][.precision *][length hh,h,ll,l,L,j,t,z][specifier d,i,u,x,X,c,s,p,%,e,f,g,n,E,F,G,a,A,C,S,o]
|
** char 1bytes 8bits
|
||||||
ft_printf % [flags 0,- ][width *][.precision *] [specifier d,i,u,x,X,c,s,p,% ]
|
** short 2bytes 16bits
|
||||||
bonus % [flags #,', ,+] [length hh,h,ll,l ][specifier e,f,g,n ]
|
** int 4bytes 32bits
|
||||||
|
** long 8bytes 64bits
|
||||||
[arg_nbr]
|
** long long 8bytes 64bits
|
||||||
( nbr$ specify the argument to access, they are numbered starting at 1
|
**
|
||||||
|
** 255 -127 - +127 00 [char] [hhd, hhi, c] [int] [d( , h, hh), i( , h, hh), c]
|
||||||
[flags] #,0,-, ,+,'
|
** 65535 -32768 - +32767 01 [short] [hd, hi] [int]
|
||||||
- left-justify within the given field width
|
** 4294967295 -2147483648 - +2147483647 02 [int] [d, i] [int]
|
||||||
0 left-pads the number with zeroes (0) instead of spaces, where
|
** 18446744073709551615 -9223372036854775808 - +9223372036854775807 04 [long] [ld, li] [long] [d(l ,ll), i(l, ll)]
|
||||||
padding is specified (see width sub-specifier)
|
** 18446744073709551615 -9223372036854775808 - +9223372036854775807 04 [long long] [lld, lli] [long]
|
||||||
( + forces to precede the result with a plus or minus sign even for
|
** 256 0 - +255 05 [unsigned char] [hhu, hhx, hhX] [unsigned int] [u( , h, hh), x( , h, hh), X( , h, hh), p]
|
||||||
positive numbers)
|
** 65536 0 - +65536 06 [unsigned short] [hu, hx, hX] [unsigned int]
|
||||||
( (space) if no sign is going to be written, a blank space is inserted
|
** 4294967296 0 - +4294967296 07 [unsigned int] [u, x, X, p] [unsigned int]
|
||||||
before the value)
|
** 18446744073709551616 0 - +18446744073709551616 09 [unsigned long] [lu, lx, lX] [unsigned long] [s, u(l, ll), x(l, ll), X(l, ll)]
|
||||||
( # (o, x, X, a, A, e, E, f, F, g, G) used with (o, x or X) the
|
** 18446744073709551616 0 - +18446744073709551616 09 [unsigned long long] [llu, llx, llX] [unsigned long]
|
||||||
value is preceded with 0, 0x or 0X for values different than
|
** 18446744073709551616 0 - +18446744073709551616 10 [char *] [s, hhn] [unsigned long]
|
||||||
zero. used with (e, E or f), it forces the written output to
|
**
|
||||||
contain a decimal point even if no digits would follow. by
|
** 18446744073709551616 0 - +18446744073709551616 16 [double] [e, le, f, lf, g, lg] []
|
||||||
default, if no digits follow, no decimal point is written. used
|
** 18446744073709551616 0 - +18446744073709551616 17 [wint_t] [lc] []
|
||||||
with (g or G) the result is the same as with e or E but trailing
|
** 18446744073709551616 0 - +18446744073709551616 18 [wchar_t] [ls] []
|
||||||
zeros are not removed
|
** 18446744073709551616 0 - +18446744073709551616 11 [short *] [hn] []
|
||||||
( ' (d, u, i, f, F) used with d, u or i, or the integral portion of
|
** 18446744073709551616 0 - +18446744073709551616 12 [int *] [n] []
|
||||||
a float f or F, the decimal conversions are printed by groups of
|
** 18446744073709551616 0 - +18446744073709551616 13 [long *] [ln] []
|
||||||
thousands separated by the non-monetary separator returned by
|
** 18446744073709551616 0 - +18446744073709551616 14 [long long *] [lln] []
|
||||||
localeconv(3) (ex 123456789 -> 123,456,789)
|
**
|
||||||
|
** d int 0 int
|
||||||
|
** dhh char 1 char
|
||||||
[specifiers] d,i,u,x,X,c,s,p,%,e,f,g,n,E,F,G,a,A,C,S,o
|
** dh short 2 short
|
||||||
c char character
|
** dl long 3 long
|
||||||
s *char string of characters
|
** dll long long 4 long long
|
||||||
p * pointer adress
|
**
|
||||||
d int (or i) signed decimal integer
|
** i int
|
||||||
i int (or d) signed decimal integer
|
** ihh char
|
||||||
u int unsigned decimal integer
|
** ih short
|
||||||
x int unsigned hexadecimal integer
|
** il long
|
||||||
X int unsigned hexadecimal integer (capital letters)
|
** ill long long
|
||||||
( n *int nothing printed
|
**
|
||||||
( f float decimal floating point
|
** u unsigned int 5 unsigned int
|
||||||
( e float scientific notation (mantissa/exponent) using e
|
** uhh unsigned char 6 unsigned char
|
||||||
( g float uses the shorter of %e or %f
|
** uh unsigned short 7 unsigned short
|
||||||
((F float
|
** ul unsigned long 8 unsigned long
|
||||||
((E float scientific notation (mantissa/exponent) using E
|
** ull unsigned long long 9 unsigned long long
|
||||||
((G float uses the shorter of %E or %f
|
**
|
||||||
((o int signed octal
|
** x unsigned int
|
||||||
((C char treated as c with l modifier
|
** xhh unsigned char
|
||||||
((a float
|
** xh unsigned short
|
||||||
((A float
|
** xl unsigned long
|
||||||
((S *char treated as s with l modifier
|
** xll unsigned long long
|
||||||
|
**
|
||||||
[width]
|
** X unsigned int
|
||||||
(nbr) minimum number of characters to be printed. if the value to be
|
** Xhh unsigned char
|
||||||
printed is shorter than this number, the result is padded with
|
** Xh unsigned short
|
||||||
blank spaces. The value is not truncated even if the result is
|
** Xl unsigned long
|
||||||
larger
|
** Xll unsigned long long
|
||||||
* the width is not specified in the format string, but as an
|
**
|
||||||
additional integer value argument preceding the argument that
|
** c char -> int
|
||||||
has to be formatted
|
** cl wint_t 10 wint_t
|
||||||
|
** s char * 11 char *
|
||||||
[.precision]
|
** sl wchar_t * 12 wchar_t *
|
||||||
.nbr fot integer specifiers (d,i,o,x,X) - precision specifies the
|
** p unsigned int
|
||||||
minimum number of digits to be written. If the value to be
|
** e double 13 double
|
||||||
written is shorter than this number, the result is padded with
|
** el
|
||||||
leading zeros. The value is not truncated even if the result is
|
** f double
|
||||||
longer. A precision of 0 means that no character is written for
|
** fl
|
||||||
the value 0. For e, E and f specifiers − this is the number of
|
** g double
|
||||||
digits to be printed after the decimal point. For g and G
|
** gl
|
||||||
specifiers − This is the maximum number of significant digits
|
**
|
||||||
to be printed. For s − this is the maximum number of characters
|
** n int * 14 int *
|
||||||
to be printed. By default all characters are printed until the
|
** nhh char *
|
||||||
ending null character is encountered. For c type − it has no
|
** nh short * 15 short *
|
||||||
effect. When no precision is specified, the default is 1. If the
|
** nl long * 16 long *
|
||||||
period is specified without an explicit value for precision, 0
|
** nll long long * 17 long long *
|
||||||
is assumed
|
**
|
||||||
.* the precision is not specified in the format string, but as an
|
** printf("char %lu\n", sizeof(char));
|
||||||
additional integer value argument preceding the argument that
|
** printf("short %lu\n", sizeof(short));
|
||||||
has to be formated
|
** printf("int %lu\n", sizeof(int));
|
||||||
|
** printf("long %lu\n", sizeof(long));
|
||||||
|
** printf("long long %lu\n", sizeof(long long));
|
||||||
|
** printf("unsigned char %lu\n", sizeof(unsigned char));
|
||||||
|
** printf("unsigned short %lu\n", sizeof(unsigned short));
|
||||||
|
** printf("unsigned int %lu\n", sizeof(unsigned int));
|
||||||
|
** printf("unsigned long %lu\n", sizeof(unsigned long));
|
||||||
|
** printf("unsigned long long %lu\n", sizeof(unsigned long long));
|
||||||
|
** printf("char * %lu\n", sizeof(char *));
|
||||||
|
** printf("short * %lu\n", sizeof(short *));
|
||||||
|
** printf("int * %lu\n", sizeof(int *));
|
||||||
|
** printf("long * %lu\n", sizeof(long *));
|
||||||
|
** printf("long long * %lu\n", sizeof(long long *));
|
||||||
|
** printf("double %lu\n", sizeof(double));
|
||||||
|
** // printf("wint_t %lu\n", sizeof(wint_t));
|
||||||
|
** // printf("wchar_T %lu\n", sizeof(wchar_t));
|
||||||
|
**
|
||||||
|
** int flag: pw+ '#-0
|
||||||
|
** 00000000 00000000 00000000 00000001 == 1 '0'
|
||||||
|
** 00000000 00000000 00000000 00000010 == 2 '-'
|
||||||
|
** 00000000 00000000 00000000 00000100 == 4 '#'
|
||||||
|
** 00000000 00000000 00000000 00001000 == 8 '''
|
||||||
|
** 00000000 00000000 00000000 00010000 == 16 ' '
|
||||||
|
** 00000000 00000000 00000000 00100000 == 32 '+'
|
||||||
|
** 00000000 00000000 00000000 01000000 == 64 '*' width
|
||||||
|
** 00000000 00000000 00000000 10000000 == 128 '*' precision
|
||||||
|
**
|
||||||
|
** typedef struct s_prist
|
||||||
|
** {
|
||||||
|
** char *str;
|
||||||
|
** int flag; // default 0 ; [0-#' +**] binary
|
||||||
|
** int width; // default 0 ;
|
||||||
|
** int prec; // default 0 ; precision
|
||||||
|
** char *length; // default "\0" ;
|
||||||
|
** char spec; // default 0 ; specifier
|
||||||
|
** char *arg; // default "\0" ;
|
||||||
|
** int p_nb; // default 0 ; print_nb : order in which to print (order it was found in string)
|
||||||
|
** int a_nb; // default 0 ; arg_nb : number of the corresponding argument (for flag $)
|
||||||
|
** struct s_prist *next;
|
||||||
|
** } t_prist;
|
||||||
|
**
|
||||||
|
** ("2 1 3 4 3", 1, 2, 3, 4)
|
||||||
|
**
|
||||||
|
** ft_error(int err)
|
||||||
|
** ft_store("%i truc %-10d machin\n")
|
||||||
|
** ft_split_print(str)
|
||||||
|
** prist->str = "%i";
|
||||||
|
** ft_fill_lst(prist)
|
||||||
|
** prist->flag; // default = 0
|
||||||
|
** prist->width; // default = 0
|
||||||
|
** prist->prec; // default = 0
|
||||||
|
** prist->length;
|
||||||
|
** prist->spec;
|
||||||
|
** prist->p_nb;
|
||||||
|
** prist->a_nb; // if not $ == p_nb
|
||||||
|
** prist->str = " truc ";
|
||||||
|
** ft_fill_lst(prist)
|
||||||
|
** ... // if str start without % it means it can be printed as a string directly
|
||||||
|
** prist->str = "%-10d";
|
||||||
|
** ft_fill_lst...
|
||||||
|
** prist->str = " machin\n";
|
||||||
|
** ft_fill_lst...
|
||||||
|
** return
|
||||||
|
** {{str; flag; width; precision; length; specifier; p_nb 1; a_nb 2},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 2; a_nb 1},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 3; a_nb 3},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 4; a_nb 4},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 5; a_nb 3}}
|
||||||
|
**
|
||||||
|
** ft_sort_by_arg
|
||||||
|
** {{str; flag; width; precision; length; specifier; p_nb 2; a_nb 1},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 1; a_nb 2},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 3; a_nb 3},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 5; a_nb 3},
|
||||||
|
** {str; flag; width; precision; length; specifier; p_nb 4; a_nb 4}}
|
||||||
|
**
|
||||||
|
** ft_add_arg
|
||||||
|
** if lst->str[o] != '\%' rerun without looking for argument
|
||||||
|
** if lst->flag == * rerun for next argument but same list element
|
||||||
|
** [fl][w][p] or or
|
||||||
|
** %i ,1 -> '1' [] [0][0] [ ][0][0] [] [0][0]
|
||||||
|
** %*i ,3,1 -> ' 1' [*] [0][0] [* ][0][0] [w] [0][0]
|
||||||
|
** %.*i ,2,1 -> '01' [*] [0][0] [ *][0][0] [p] [0][0]
|
||||||
|
** %*.*i ,3,2,1 -> ' 01' [**][0][0] [**][0][0] [wp][0][0]
|
||||||
|
** %3.*i ,2,1 -> ' 01' [*] [3][0] [ *][3][0] [p] [3][0]
|
||||||
|
** %*.2i ,3,1 -> ' 01' [*] [0][2] [* ][0][2] [w] [0][2]
|
||||||
|
** %3.2i ,1 -> ' 01' [] [3][2] [ ][3][2] [] [3][2]
|
||||||
|
** if lst->next->a_nb == lst->a_nb rerun for next list element but same argument
|
||||||
|
** {{str; flag; width; precision; length; specifier; arg; p_nb 2; a_nb 1},
|
||||||
|
** {str; flag; width; precision; length; specifier; arg; p_nb 1; a_nb 2},
|
||||||
|
** {str; flag; width; precision; length; specifier; arg; p_nb 3; a_nb 3},
|
||||||
|
** {str; flag; width; precision; length; specifier; arg; p_nb 5; a_nb 3},
|
||||||
|
** {str; flag; width; precision; length; specifier; arg; p_nb 4; a_nb 4}}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2020/02/19 16:23:01 by hulamy #+# #+# */
|
/* Created: 2020/02/19 16:23:01 by hulamy #+# #+# */
|
||||||
/* Updated: 2020/02/19 18:44:21 by hulamy ### ########.fr */
|
/* Updated: 2020/02/20 13:03:34 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
/*
|
/*
|
||||||
** SPECIFIER :
|
** SPECIFIER :
|
||||||
** receive a word as a string, check if it start by '%', and return the
|
** receive a word as a string, check if it start by '%', and return the
|
||||||
** specifier (diuxXspefgn) and th length (h hh l ll)
|
** specifier (diuxXspefgn) and the length (h hh l ll)
|
||||||
** -if s is a string, or is a single '%'
|
** -if s is a string, or is a single '%'
|
||||||
** return NULL (to print is as a string)
|
** return NULL (to print is as a string)
|
||||||
** -if s is a double '%%', remove one '%', and
|
** -if s is a double '%%', remove one '%', and
|
||||||
Reference in New Issue
Block a user