diff --git a/ft_printf b/ft_printf index ad601ec..574921d 100755 Binary files a/ft_printf and b/ft_printf differ diff --git a/main.c b/main.c index 1d00cac..3f173e7 100644 --- a/main.c +++ b/main.c @@ -265,6 +265,8 @@ int main(int ac, char **av) PRINT("%10s", "strxng"); //PRINT("%010s", "strzng"); // '0' not compatible with string PRINT("%s" "__TEST__", "strzng"); + char *s = "hess"; + PRINT("%s", s) } /* ////////////////////////////////////////////////////////////////// */ @@ -463,6 +465,11 @@ int main(int ac, char **av) PRINT("%p", s) s = "truc"; PRINT("%p", s) + unsigned int u = 4; + PRINT("%p", &u) + PRINT("%s-%p", s, s) + PRINT("%u-%p", u, &u) + PRINT("%up", u) } if (ac == 2 || !strcmp(av[2], "%")) @@ -517,6 +524,10 @@ int main(int ac, char **av) PRINT("%#.10X", 8645); PRINT("%#10.10X", 8645); PRINT("%#010X", 8645); + unsigned int uu = 4; + PRINT("%#X", (unsigned int)&uu) + PRINT("%#x", (unsigned int)&uu) + PRINT("%#lx", (unsigned long int)&uu) } if (ac == 2 || !strcmp(av[2], "'")) diff --git a/outf.txt b/outf.txt index 88c2018..5c94524 100644 --- a/outf.txt +++ b/outf.txt @@ -1 +1 @@ -0x10ac97cb7 +33333 diff --git a/outft.txt b/outft.txt index 9d46009..5c94524 100644 --- a/outft.txt +++ b/outft.txt @@ -1 +1 @@ -ac97cb7 +33333 diff --git a/srcs/ft_convert.c b/srcs/ft_convert.c index 6013994..0e49955 100644 --- a/srcs/ft_convert.c +++ b/srcs/ft_convert.c @@ -6,14 +6,13 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/27 12:03:28 by hulamy #+# #+# */ -/* Updated: 2020/02/27 12:03:38 by hulamy ### ########.fr */ +/* Updated: 2020/02/27 17:34:06 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" /* -** FT_CONVERT : ** -convert the next argument into a string according to the following ** correspondances for diuxXcspefgn : ** [char] [hhd, hhi, c] [int] [d i c] @@ -69,6 +68,17 @@ char *conv_u(char c, unsigned long int i) return (NULL); } +/* +** -for each kind of specifier there is finally four kinds of conversion : +** int / long int / unsigned int / unsingned long int +** -the conversion 'uxX' associated with 'l' are converted with lu, but +** also are 'p' and 's', without an 'l' flag, that's why there is this little +** trick on line the line for unsigned int : +** -'uxXps' && 'lps' will make it looks for 'uxX' and for 'l' +** (because it will never find a 'p' or a 's' if there are 'uxX' already) +** or for 'p' and again for 'p', or 's' twice similarly +*/ + char *ft_convert(va_list ap, char *type) { char *s; @@ -77,12 +87,10 @@ char *ft_convert(va_list ap, char *type) return (conv_i(s[0], va_arg(ap, long int))); if ((s = ft_strchrset(type, "dic"))) return (conv_i(s[0], va_arg(ap, int))); - if ((s = ft_strchrset(type, "uxX")) && ft_strchr(type, 'l')) + if ((s = ft_strchrset(type, "uxXps")) && ft_strchrset(type, "lps")) return (conv_u(s[0], va_arg(ap, unsigned long int))); - if ((s = ft_strchrset(type, "uxXp"))) + if ((s = ft_strchrset(type, "uxX"))) return (conv_u(s[0], va_arg(ap, unsigned int))); - if ((s = ft_strchrset(type, "s"))) - return (conv_u(s[0], va_arg(ap, unsigned long int))); if (ft_strchr(type, '%')) return (ft_strdup("%")); if (ft_strchrset(type, "efgn")) diff --git a/srcs/ft_flag_transform.c b/srcs/ft_flag_transform.c index 6036ffa..df604ef 100644 --- a/srcs/ft_flag_transform.c +++ b/srcs/ft_flag_transform.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/27 11:55:43 by hulamy #+# #+# */ -/* Updated: 2020/02/27 12:07:22 by hulamy ### ########.fr */ +/* Updated: 2020/02/27 18:17:34 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -155,12 +155,15 @@ char *ft_width(char *s, char *print) } /* -** go through all the transformation flags needs +** -go through all the transformation flags needs +** -the case of 'p' is treated without any subtelness because i don't care */ char *ft_flag_transform(char *s, char *print, char *type) { print = ft_precision(s, print, type); print = ft_width(s, print); + if (ft_strchr(type, 'p')) + print = ft_concat_free(ft_strdup("0x"), print); return (print); }