specifier p ok

This commit is contained in:
Hugo LAMY
2020-02-27 18:18:54 +01:00
parent 53bcaad780
commit b43227703f
6 changed files with 32 additions and 10 deletions

BIN
ft_printf

Binary file not shown.

11
main.c
View File

@@ -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], "'"))

View File

@@ -1 +1 @@
0x10ac97cb7
33333

View File

@@ -1 +1 @@
ac97cb7
33333

View File

@@ -6,14 +6,13 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"))

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}