Files
ft_printf/libftprintf/ft_vprintf_string.c
2022-04-29 08:46:53 +02:00

54 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vprintf_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
/* Updated: 2022/04/29 08:42:02 by gbaconni ### lausanne.ch */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
int ft_vprintf_string(const char *format, va_list ap)
{
int ret;
char *s;
(void) format;
ret = 0;
s = va_arg(ap, char *);
if (s == NULL)
{
ret = ft_puts("(null)");
return (ret);
}
const char *f;
int precision;
int len;
int flags;
precision = 0;
flags = ft_vprintf_flags_bonus(format, ap);
(void) flags;
f = format;
while (*f != '\0')
{
if (ft_isdigit(*f))
precision = precision * 10 + *f - '0';
if (ft_strchr("cspdiuxX%", *f) != NULL)
break ;
f++;
}
if (precision > 0)
{
len = precision - ft_strlen(s);
while (len --> 0)
ret += ft_putchar(' ');
}
ret += ft_puts(s);
return (ret);
}