amelioration tests et explication dans main, et amelioration ecriture printf en pseudo code
This commit is contained in:
BIN
.ft_printf.c.swn
Normal file
BIN
.ft_printf.c.swn
Normal file
Binary file not shown.
283
ft_printf.c
283
ft_printf.c
@@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
#include "ft_printf.h"
|
#include "ft_printf.h"
|
||||||
|
#include <libc.h>
|
||||||
|
|
||||||
int ft_error(int i)
|
//int ft_error(int i)
|
||||||
{
|
//{
|
||||||
if (i == 0)
|
// if (i == 0)
|
||||||
return (1);
|
// return (1);
|
||||||
return (0);
|
// return (0);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
%[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]
|
%[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]
|
||||||
@@ -43,43 +43,98 @@ while ((s = next_word(str)) != NULL)
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
char *ft_nextword(char *str)
|
|
||||||
{
|
|
||||||
char *word;
|
|
||||||
|
|
||||||
word = strdup(str);
|
//char *ft_nextword(char *str)
|
||||||
return (word);
|
//{
|
||||||
}
|
// char *word;
|
||||||
|
//
|
||||||
|
// word = strdup(str);
|
||||||
|
// return (word);
|
||||||
|
//}
|
||||||
|
|
||||||
t_prist *ft_store(char *str)
|
//t_prist *ft_store(char *str)
|
||||||
{
|
//{
|
||||||
t_prist *lst;
|
// t_prist *lst;
|
||||||
t_prist *lstmp;
|
// t_prist *lstmp;
|
||||||
char *tmp;
|
// char *tmp;
|
||||||
|
//
|
||||||
|
// lst = NULL;
|
||||||
|
// while (*str != '\0')
|
||||||
|
// {
|
||||||
|
// lstmp = lst;
|
||||||
|
// (*lst) = (t_prist *)malloc(sizeof(*lst));
|
||||||
|
// tmp = ft_nextword(str);
|
||||||
|
// (*arglst)->str = ft_strdup(tmp);
|
||||||
|
// ...fill_flag...;
|
||||||
|
// if (tmp != NULL)
|
||||||
|
// tmp[0] = '%';
|
||||||
|
// str = tmp;
|
||||||
|
// lst->next = lstmp;
|
||||||
|
// }
|
||||||
|
// return (lst);
|
||||||
|
//}
|
||||||
|
|
||||||
lst = NULL;
|
/*
|
||||||
while (*str != '\0')
|
** char *print; | -contain the arg converted into a string
|
||||||
{
|
** char *type; | -contain the specifier type to use
|
||||||
lstmp = lst;
|
** | by va_arg
|
||||||
(*lst) = (t_prist *)malloc(sizeof(*lst));
|
** while s = next_word() | -return the next sequence to be print
|
||||||
tmp = ft_nextword(str);
|
** | (either a string, or a conversion)
|
||||||
(*arglst)->str = ft_strdup(tmp);
|
** type = ft_specifier(&s) | -return the type if it's a conversion,
|
||||||
...fill_flag...;
|
** | or NULL if it's a string.
|
||||||
if (tmp != NULL)
|
** | if convers0, rmvs length & specifier from s
|
||||||
tmp[0] = '%';
|
** if !type: ft_put_word() | -print the string if it wasn't a conversion
|
||||||
str = tmp;
|
** while flag_*(s) | -for each * present, expand it into s
|
||||||
lst->next = lstmp;
|
** ft_expand_star() | in order it appears
|
||||||
}
|
** print = ft_convert() | -convert the arg with its type,
|
||||||
return (lst);
|
** | then trsfm it into a str and rtrn the str
|
||||||
}
|
** ft_flag_transform() | -proceed all modification according to flags
|
||||||
|
** ft_put_word(print) | -print the string fully converted
|
||||||
|
** return (length) | -return the length of what was printed
|
||||||
|
*/
|
||||||
|
|
||||||
int ft_printf(char *string, ...)
|
int ft_printf(char *string, ...)
|
||||||
{
|
{
|
||||||
|
char *print;
|
||||||
|
char *type;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
length = 0;
|
||||||
|
while ((s = next_word(str)) != NULL)
|
||||||
|
{
|
||||||
|
if (!(type = ft_specifier(&s)))
|
||||||
|
lentgh += ft_put_word(s);
|
||||||
|
while (flag_*(s))
|
||||||
|
ft_expand_star(va_arg(ap, int), &s);
|
||||||
|
print = ft_convert(va_arg(ap, type), type);
|
||||||
|
print = ft_flag_transform(s, print);
|
||||||
|
length += ft_put_word(print);
|
||||||
|
}
|
||||||
|
return (length)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ft_flag_transform()
|
||||||
|
// {
|
||||||
|
// if ((i = flag_p(&s))) // precision is calculated before width, if its on string it cuts it if smaller than it,
|
||||||
|
// print = ft_precision(i, print); // and on numbers it add '0' before it if bigger, then add minus sign if negatif (if precision is given with flags - or 0 they're ignored and cuted from s)
|
||||||
|
// if ((i = flag_w(s))) //
|
||||||
|
// {
|
||||||
|
// if (flag_-(s))
|
||||||
|
// print = ft_right_padded(i, print);
|
||||||
|
// else if (flag_0(s))
|
||||||
|
// print = ft_left_padded(i, print);
|
||||||
|
// }
|
||||||
|
// // if (flag_+(s))
|
||||||
|
// // else if (flag_space(s))
|
||||||
|
// // if (flag_'(s))
|
||||||
|
// // if (flag_#(s))
|
||||||
|
// // print = ft_alternate_form(print)
|
||||||
|
// }
|
||||||
|
|
||||||
t_prist *lst;
|
t_prist *lst;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, string);
|
va_start(ap, string);
|
||||||
lst = ft_store(string);
|
|
||||||
while (*string != '\0')
|
while (*string != '\0')
|
||||||
{
|
{
|
||||||
if (*string == 's')
|
if (*string == 's')
|
||||||
@@ -107,11 +162,28 @@ int main(void)
|
|||||||
i = 6;
|
i = 6;
|
||||||
printf("%s-%s-%c-%i\n\n", s, str, c, i);
|
printf("%s-%s-%c-%i\n\n", s, str, c, i);
|
||||||
ft_printf(s, c, str, i);
|
ft_printf(s, c, str, i);
|
||||||
|
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));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
conversions : cspdiuxX%
|
conversions : cspdiuxX%
|
||||||
flags : - 0 . *
|
flags : - 0 . *
|
||||||
conversions : nfge
|
conversions : nfge
|
||||||
@@ -121,80 +193,79 @@ conversions : nfge
|
|||||||
% [flags 0,- ][width *][.precision *] [specifier d,i,u,x,X,c,s,p,% ]
|
% [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 #,', ,+] [length hh,h,ll,l ][specifier e,f,g,n ]
|
||||||
|
|
||||||
int flag: pw+ '#-0
|
p == long unsigned int
|
||||||
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 1bytes 8bits
|
||||||
{
|
short 2bytes 16bits
|
||||||
char *str;
|
int 4bytes 32bits
|
||||||
int flag; // default 0 ; [0-#' +**] binary
|
long 8bytes 64bits
|
||||||
int width; // default 0 ;
|
long long 8bytes 64bits
|
||||||
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)
|
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 long] [u( , h, hh, l, ll), x( , h, hh, l, ll), X( , h, hh, l, ll), p]
|
||||||
|
65536 0 - +65536 06 [unsigned short] [hu, hx, hX] [unsigned long]
|
||||||
|
4294967296 0 - +4294967296 07 [unsigned int] [u, x, X, p] [unsigned long]
|
||||||
|
18446744073709551616 0 - +18446744073709551616 09 [unsigned long] [lu, lx, lX] [unsigned long]
|
||||||
|
18446744073709551616 0 - +18446744073709551616 09 [unsigned long long] [llu, llx, llX] [unsigned long]
|
||||||
|
18446744073709551616 0 - +18446744073709551616 10 [char *] [s, hhn] [char *] [s]
|
||||||
|
|
||||||
ft_error(int err)
|
18446744073709551616 0 - +18446744073709551616 16 [double] [e, le, f, lf, g, lg] []
|
||||||
ft_store("%i truc %-10d machin\n")
|
18446744073709551616 0 - +18446744073709551616 17 [wint_t] [lc] []
|
||||||
ft_split_print(str)
|
18446744073709551616 0 - +18446744073709551616 18 [wchar_t] [ls] []
|
||||||
prist->str = "%i";
|
18446744073709551616 0 - +18446744073709551616 11 [short *] [hn] []
|
||||||
ft_fill_lst(prist)
|
18446744073709551616 0 - +18446744073709551616 12 [int *] [n] []
|
||||||
prist->flag; // default = 0
|
18446744073709551616 0 - +18446744073709551616 13 [long *] [ln] []
|
||||||
prist->width; // default = 0
|
18446744073709551616 0 - +18446744073709551616 14 [long long *] [lln] []
|
||||||
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
|
d int 0 int
|
||||||
{{str; flag; width; precision; length; specifier; p_nb 2; a_nb 1},
|
dhh char 1 char
|
||||||
{str; flag; width; precision; length; specifier; p_nb 1; a_nb 2},
|
dh short 2 short
|
||||||
{str; flag; width; precision; length; specifier; p_nb 3; a_nb 3},
|
dl long 3 long
|
||||||
{str; flag; width; precision; length; specifier; p_nb 5; a_nb 3},
|
dll long long 4 long long
|
||||||
{str; flag; width; precision; length; specifier; p_nb 4; a_nb 4}}
|
|
||||||
|
|
||||||
ft_add_arg
|
i int
|
||||||
if lst->str[o] != '\%' rerun without looking for argument
|
ihh char
|
||||||
if lst->flag == * rerun for next argument but same list element
|
ih short
|
||||||
[fl][w][p] or or
|
il long
|
||||||
%i ,1 -> '1' [] [0][0] [ ][0][0] [] [0][0]
|
ill long long
|
||||||
%*i ,3,1 -> ' 1' [*] [0][0] [* ][0][0] [w] [0][0]
|
|
||||||
%.*i ,2,1 -> '01' [*] [0][0] [ *][0][0] [p] [0][0]
|
u unsigned int 5 unsigned int
|
||||||
%*.*i ,3,2,1 -> ' 01' [**][0][0] [**][0][0] [wp][0][0]
|
uhh unsigned char 6 unsigned char
|
||||||
%3.*i ,2,1 -> ' 01' [*] [3][0] [ *][3][0] [p] [3][0]
|
uh unsigned short 7 unsigned short
|
||||||
%*.2i ,3,1 -> ' 01' [*] [0][2] [* ][0][2] [w] [0][2]
|
ul unsigned long 8 unsigned long
|
||||||
%3.2i ,1 -> ' 01' [] [3][2] [ ][3][2] [] [3][2]
|
ull unsigned long long 9 unsigned long long
|
||||||
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},
|
x unsigned int
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 1; a_nb 2},
|
xhh unsigned char
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 3; a_nb 3},
|
xh unsigned short
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 5; a_nb 3},
|
xl unsigned long
|
||||||
{str; flag; width; precision; length; specifier; arg; p_nb 4; a_nb 4}}
|
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 *
|
||||||
*/
|
*/
|
||||||
|
|||||||
292
main.c
292
main.c
@@ -94,7 +94,7 @@ int main(void)
|
|||||||
printf("(\"%%i\",0x1E240) : "); printf("%i\n", 0x1E240); printf("\n");
|
printf("(\"%%i\",0x1E240) : "); printf("%i\n", 0x1E240); printf("\n");
|
||||||
|
|
||||||
printf("-----------------------------------------------\n");
|
printf("-----------------------------------------------\n");
|
||||||
printf("- flags : -,0,.,* -\n");
|
printf("- flags : -0.* -\n");
|
||||||
printf("- taille de champ minimale -\n");
|
printf("- taille de champ minimale -\n");
|
||||||
printf("-----------------------------------------------\n\n");
|
printf("-----------------------------------------------\n\n");
|
||||||
|
|
||||||
@@ -118,6 +118,9 @@ int main(void)
|
|||||||
// printf("(\"%%0i\",0) ft : "); ft_printf("'%0i'\n", 0);
|
// printf("(\"%%0i\",0) ft : "); ft_printf("'%0i'\n", 0);
|
||||||
printf("(\"%%0i\",0) : "); printf("'%0i'\n", 0); printf("\n");
|
printf("(\"%%0i\",0) : "); printf("'%0i'\n", 0); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%6i\",-456) ft : "); ft_printf("'%6i'\n", -456);
|
||||||
|
printf("(\"%%6i\",-456) : "); printf("'%6i'\n", -456); printf("\n");
|
||||||
|
|
||||||
printf("- flag - --------------------------------------\n\n");
|
printf("- flag - --------------------------------------\n\n");
|
||||||
|
|
||||||
// printf("(\"%%-3s\",\"a\") ft : "); ft_printf("'%-3s'\n", "a");
|
// printf("(\"%%-3s\",\"a\") ft : "); ft_printf("'%-3s'\n", "a");
|
||||||
@@ -146,11 +149,37 @@ int main(void)
|
|||||||
// printf("(\"%%03i\",1) ft : "); ft_printf("'%03i'\n", 1);
|
// printf("(\"%%03i\",1) ft : "); ft_printf("'%03i'\n", 1);
|
||||||
printf("(\"%%03i\",1) : "); printf("'%03i'\n", 1); printf("\n");
|
printf("(\"%%03i\",1) : "); printf("'%03i'\n", 1); printf("\n");
|
||||||
|
|
||||||
printf("- flag . --------------------------------------\n\n");
|
// printf("(\"%%09i\",\"123456\") ft : "); ft_printf("'%09s'\n", "123456");
|
||||||
|
// printf("(\"%%09i\",\"123456\") : "); printf("'%09s'\n", "123456"); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%03i\",1) ft : "); ft_printf("'%03i'\n", 1);
|
||||||
|
printf("(\"%%03i\",1) : "); printf("'%03i'\n", 1); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%03i\",1) ft : "); ft_printf("'%03i'\n", 1);
|
||||||
|
printf("(\"%%03i\",1) : "); printf("'%03i'\n", 1); printf("\n");
|
||||||
|
|
||||||
|
printf("- flag . (diouxXs) ----------------------------------------------------------\n");
|
||||||
|
printf("- if the . is not followed by a number, the value is 0\n");
|
||||||
|
printf("- with arg value of 0, precision of 0 print nothing\n");
|
||||||
|
printf("- with numbers (diouxX), gives the minimum number of digit to appear\n");
|
||||||
|
printf("- if precision > nbr, it's preceded by '0'\n");
|
||||||
|
printf("- if nbr < 0, '-' is not counted in precision\n");
|
||||||
|
printf("- (length with '-' is (length(nbr or precision) + 1)'\n");
|
||||||
|
printf("- if 0 flag is given (for width or precision) it's ignored\n");
|
||||||
|
printf("- with strings (s), gives the maximum number of characters to be print\n");
|
||||||
|
printf("- if precision > length(s), it's not preceded by '0'\n");
|
||||||
|
printf("- precision is calculated before width\n");
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
// printf("(\"%%.5s\",\"12\") ft : "); ft_printf("'%.5s'\n", "12");
|
// printf("(\"%%.5s\",\"12\") ft : "); ft_printf("'%.5s'\n", "12");
|
||||||
printf("(\"%%.5s\",\"12\") : "); printf("'%.5s'\n", "12"); printf("\n");
|
printf("(\"%%.5s\",\"12\") : "); printf("'%.5s'\n", "12"); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%.5s\",\"12345678\") ft : "); ft_printf("'%.5s'\n", "12345678");
|
||||||
|
printf("(\"%%.5s\",\"12345678\") : "); printf("'%.5s'\n", "12345678"); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%12.5s\",\"12345678\") ft : "); ft_printf("'%12.5s'\n", "12345678");
|
||||||
|
printf("(\"%%12.5s\",\"12345678\") : "); printf("'%12.5s'\n", "12345678"); printf("\n");
|
||||||
|
|
||||||
// printf("(\"%%.5i\",12) ft : "); ft_printf("'%.5i'\n", 12);
|
// printf("(\"%%.5i\",12) ft : "); ft_printf("'%.5i'\n", 12);
|
||||||
printf("(\"%%.5i\",12) : "); printf("'%.5i'\n", 12); printf("\n");
|
printf("(\"%%.5i\",12) : "); printf("'%.5i'\n", 12); printf("\n");
|
||||||
|
|
||||||
@@ -178,6 +207,9 @@ int main(void)
|
|||||||
// printf("(\"%%.i\",0) ft : "); ft_printf("'%.i'\n", 0);
|
// printf("(\"%%.i\",0) ft : "); ft_printf("'%.i'\n", 0);
|
||||||
printf("(\"%%.i\",0) : "); printf("'%.i'\n", 0); printf("\n");
|
printf("(\"%%.i\",0) : "); printf("'%.i'\n", 0); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%i\",0) ft : "); ft_printf("'%i'\n", 0);
|
||||||
|
printf("(\"%%i\",0) : "); printf("'%i'\n", 0); printf("\n");
|
||||||
|
|
||||||
// printf("(\"%%010.7X\",8645) ft : "); ft_printf("'%010.7X'\n", 8645);
|
// printf("(\"%%010.7X\",8645) ft : "); ft_printf("'%010.7X'\n", 8645);
|
||||||
printf("(\"%%010.7X\",8645) : "); printf("'%010.7X'\n", 8645); printf("\n");
|
printf("(\"%%010.7X\",8645) : "); printf("'%010.7X'\n", 8645); printf("\n");
|
||||||
|
|
||||||
@@ -187,8 +219,14 @@ int main(void)
|
|||||||
// printf("(\"%%-10.7X\",8645) ft : "); ft_printf("'%-10.7X'\n", 8645);
|
// printf("(\"%%-10.7X\",8645) ft : "); ft_printf("'%-10.7X'\n", 8645);
|
||||||
printf("(\"%%-10.7X\",8645) : "); printf("'%-10.7X'\n", 8645); printf("\n");
|
printf("(\"%%-10.7X\",8645) : "); printf("'%-10.7X'\n", 8645); printf("\n");
|
||||||
|
|
||||||
// printf("(\"%%-.7X\",8645) ft : "); ft_printf("'%-.7X'\n", 8645);
|
// printf("(\"%%-.7i\",8645) ft : "); ft_printf("'%-.7i'\n", 8645);
|
||||||
printf("(\"%%-.7X\",8645) : "); printf("'%-.7X'\n", 8645); printf("\n");
|
printf("(\"%%-.7i\",8645) : "); printf("'%-.7i'\n", 8645); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%.7i\",-8645) ft : "); ft_printf("'%.7i'\n", -8645);
|
||||||
|
printf("(\"%%.7i\",-8645) : "); printf("'%.7i'\n", -8645); printf("\n");
|
||||||
|
|
||||||
|
// printf("(\"%%.07i\",8645) ft : "); ft_printf("'%.07i'\n", 8645);
|
||||||
|
printf("(\"%%.07i\",8645) : "); printf("'%.07i'\n", 8645); printf("\n");
|
||||||
|
|
||||||
printf("- flag * --------------------------------------\n\n");
|
printf("- flag * --------------------------------------\n\n");
|
||||||
|
|
||||||
@@ -283,87 +321,165 @@ int main(void)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// conversions : cspdiuxX%
|
/*
|
||||||
// flags : -,0,.,*
|
int flag: pw+ '#-0
|
||||||
// conversions : nfge
|
00000000 00000000 00000000 00000001 == 1 '0'
|
||||||
// flags : l,ll,h,hh,#,', ,+
|
00000000 00000000 00000000 00000010 == 2 '-'
|
||||||
//
|
00000000 00000000 00000000 00000100 == 4 '#'
|
||||||
// usage :
|
00000000 00000000 00000000 00001000 == 8 '''
|
||||||
// %[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 00010000 == 16 ' '
|
||||||
// % [flags 0,- ][width *][.precision *] [specifier d,i,u,x,X,c,s,p,% ]
|
00000000 00000000 00000000 00100000 == 32 '+'
|
||||||
// % [flags #,', ,+] [length hh,h,ll,l ][specifier e,f,g,n ]
|
00000000 00000000 00000000 01000000 == 64 '*' width
|
||||||
//
|
00000000 00000000 00000000 10000000 == 128 '*' precision
|
||||||
// [arg_nbr]
|
|
||||||
//( nbr$ specify the argument to access, they are numbered starting at 1
|
typedef struct s_prist
|
||||||
//
|
{
|
||||||
// [flags] #,0,-, ,+,'
|
char *str;
|
||||||
// - left-justify within the given field width
|
int flag; // default 0 ; [0-#' +**] binary
|
||||||
// 0 left-pads the number with zeroes (0) instead of spaces, where
|
int width; // default 0 ;
|
||||||
// padding is specified (see width sub-specifier)
|
int prec; // default 0 ; precision
|
||||||
//( + forces to precede the result with a plus or minus sign even for
|
char *length; // default "\0" ;
|
||||||
// positive numbers)
|
char spec; // default 0 ; specifier
|
||||||
//( (space) if no sign is going to be written, a blank space is inserted
|
char *arg; // default "\0" ;
|
||||||
// before the value)
|
int p_nb; // default 0 ; print_nb : order in which to print (order it was found in string)
|
||||||
//( # (o, x, X, a, A, e, E, f, F, g, G) used with (o, x or X) the
|
int a_nb; // default 0 ; arg_nb : number of the corresponding argument (for flag $)
|
||||||
// value is preceded with 0, 0x or 0X for values different than
|
struct s_prist *next;
|
||||||
// zero. used with (e, E or f), it forces the written output to
|
} t_prist;
|
||||||
// contain a decimal point even if no digits would follow. by
|
|
||||||
// default, if no digits follow, no decimal point is written. used
|
("2 1 3 4 3", 1, 2, 3, 4)
|
||||||
// with (g or G) the result is the same as with e or E but trailing
|
|
||||||
// zeros are not removed
|
ft_error(int err)
|
||||||
//( ' (d, u, i, f, F) used with d, u or i, or the integral portion of
|
ft_store("%i truc %-10d machin\n")
|
||||||
// a float f or F, the decimal conversions are printed by groups of
|
ft_split_print(str)
|
||||||
// thousands separated by the non-monetary separator returned by
|
prist->str = "%i";
|
||||||
// localeconv(3) (ex 123456789 -> 123,456,789)
|
ft_fill_lst(prist)
|
||||||
//
|
prist->flag; // default = 0
|
||||||
//
|
prist->width; // default = 0
|
||||||
// [specifiers] d,i,u,x,X,c,s,p,%,e,f,g,n,E,F,G,a,A,C,S,o
|
prist->prec; // default = 0
|
||||||
// c char character
|
prist->length;
|
||||||
// s *char string of characters
|
prist->spec;
|
||||||
// p * pointer adress
|
prist->p_nb;
|
||||||
// d int (or i) signed decimal integer
|
prist->a_nb; // if not $ == p_nb
|
||||||
// i int (or d) signed decimal integer
|
prist->str = " truc ";
|
||||||
// u int unsigned decimal integer
|
ft_fill_lst(prist)
|
||||||
// x int unsigned hexadecimal integer
|
... // if str start without % it means it can be printed as a string directly
|
||||||
// X int unsigned hexadecimal integer (capital letters)
|
prist->str = "%-10d";
|
||||||
//( n *int nothing printed
|
ft_fill_lst...
|
||||||
//( f float decimal floating point
|
prist->str = " machin\n";
|
||||||
//( e float scientific notation (mantissa/exponent) using e
|
ft_fill_lst...
|
||||||
//( g float uses the shorter of %e or %f
|
return
|
||||||
//((F float
|
{{str; flag; width; precision; length; specifier; p_nb 1; a_nb 2},
|
||||||
//((E float scientific notation (mantissa/exponent) using E
|
{str; flag; width; precision; length; specifier; p_nb 2; a_nb 1},
|
||||||
//((G float uses the shorter of %E or %f
|
{str; flag; width; precision; length; specifier; p_nb 3; a_nb 3},
|
||||||
//((o int signed octal
|
{str; flag; width; precision; length; specifier; p_nb 4; a_nb 4},
|
||||||
//((C char treated as c with l modifier
|
{str; flag; width; precision; length; specifier; p_nb 5; a_nb 3}}
|
||||||
//((a float
|
|
||||||
//((A float
|
ft_sort_by_arg
|
||||||
//((S *char treated as s with l modifier
|
{{str; flag; width; precision; length; specifier; p_nb 2; a_nb 1},
|
||||||
//
|
{str; flag; width; precision; length; specifier; p_nb 1; a_nb 2},
|
||||||
// [width]
|
{str; flag; width; precision; length; specifier; p_nb 3; a_nb 3},
|
||||||
// (nbr) minimum number of characters to be printed. if the value to be
|
{str; flag; width; precision; length; specifier; p_nb 5; a_nb 3},
|
||||||
// printed is shorter than this number, the result is padded with
|
{str; flag; width; precision; length; specifier; p_nb 4; a_nb 4}}
|
||||||
// blank spaces. The value is not truncated even if the result is
|
|
||||||
// larger
|
ft_add_arg
|
||||||
// * the width is not specified in the format string, but as an
|
if lst->str[o] != '\%' rerun without looking for argument
|
||||||
// additional integer value argument preceding the argument that
|
if lst->flag == * rerun for next argument but same list element
|
||||||
// has to be formatted
|
[fl][w][p] or or
|
||||||
//
|
%i ,1 -> '1' [] [0][0] [ ][0][0] [] [0][0]
|
||||||
// [.precision]
|
%*i ,3,1 -> ' 1' [*] [0][0] [* ][0][0] [w] [0][0]
|
||||||
// .nbr fot integer specifiers (d,i,o,x,X) - precision specifies the
|
%.*i ,2,1 -> '01' [*] [0][0] [ *][0][0] [p] [0][0]
|
||||||
// minimum number of digits to be written. If the value to be
|
%*.*i ,3,2,1 -> ' 01' [**][0][0] [**][0][0] [wp][0][0]
|
||||||
// written is shorter than this number, the result is padded with
|
%3.*i ,2,1 -> ' 01' [*] [3][0] [ *][3][0] [p] [3][0]
|
||||||
// leading zeros. The value is not truncated even if the result is
|
%*.2i ,3,1 -> ' 01' [*] [0][2] [* ][0][2] [w] [0][2]
|
||||||
// longer. A precision of 0 means that no character is written for
|
%3.2i ,1 -> ' 01' [] [3][2] [ ][3][2] [] [3][2]
|
||||||
// the value 0. For e, E and f specifiers − this is the number of
|
if lst->next->a_nb == lst->a_nb rerun for next list element but same argument
|
||||||
// digits to be printed after the decimal point. For g and G
|
{{str; flag; width; precision; length; specifier; arg; p_nb 2; a_nb 1},
|
||||||
// specifiers − This is the maximum number of significant digits
|
{str; flag; width; precision; length; specifier; arg; p_nb 1; a_nb 2},
|
||||||
// to be printed. For s − this is the maximum number of characters
|
{str; flag; width; precision; length; specifier; arg; p_nb 3; a_nb 3},
|
||||||
// to be printed. By default all characters are printed until the
|
{str; flag; width; precision; length; specifier; arg; p_nb 5; a_nb 3},
|
||||||
// ending null character is encountered. For c type − it has no
|
{str; flag; width; precision; length; specifier; arg; p_nb 4; a_nb 4}}
|
||||||
// effect. When no precision is specified, the default is 1. If the
|
|
||||||
// period is specified without an explicit value for precision, 0
|
conversions : cspdiuxX%
|
||||||
// is assumed
|
flags : -,0,.,*
|
||||||
// .* the precision is not specified in the format string, but as an
|
conversions : nfge
|
||||||
// additional integer value argument preceding the argument that
|
flags : l,ll,h,hh,#,', ,+
|
||||||
// has to be formated
|
|
||||||
//
|
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]
|
||||||
|
ft_printf % [flags 0,- ][width *][.precision *] [specifier d,i,u,x,X,c,s,p,% ]
|
||||||
|
bonus % [flags #,', ,+] [length hh,h,ll,l ][specifier e,f,g,n ]
|
||||||
|
|
||||||
|
[arg_nbr]
|
||||||
|
( nbr$ specify the argument to access, they are numbered starting at 1
|
||||||
|
|
||||||
|
[flags] #,0,-, ,+,'
|
||||||
|
- 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)
|
||||||
|
|
||||||
|
|
||||||
|
[specifiers] d,i,u,x,X,c,s,p,%,e,f,g,n,E,F,G,a,A,C,S,o
|
||||||
|
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 int unsigned decimal integer
|
||||||
|
x int unsigned hexadecimal integer
|
||||||
|
X 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
|
||||||
|
|
||||||
|
[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
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user