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

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"))