libftx/printf/ft_vdprintf.c

55 lines
1.5 KiB
C
Raw Permalink Normal View History

2023-01-19 11:33:26 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vdprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 14:34:28 by cchauvet #+# #+# */
/* Updated: 2022/12/11 19:23:34 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_dprintseg(int fd, const char *str)
{
int i;
i = 0;
while (str[i] != '\0' && ft_skipflag(str + i) == 0)
{
ft_putchar_fd(fd, str[i]);
i++;
}
return (i);
}
int ft_vdprintf(int fd, const char *format, va_list va)
{
int i;
int upi;
if (format == NULL)
return (-1);
i = 0;
while (format[0] != 0)
{
if (ft_skipflag(format) == 0)
{
upi = ft_dprintseg(fd, format);
format += upi;
i += upi;
}
else
{
upi = ft_dprintflag(fd, format, va);
if (upi == -1)
return (-1);
format += ft_skipflag(format);
i += upi;
}
}
return (i);
}