Files
ft_printf/libftprintf/ft_ischr.c

54 lines
1.6 KiB
C
Raw Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vprintf_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
/* Updated: 2022/04/26 18:41:30 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 (*f >= '0' && *f <= '9')
precision = precision * 10 + *f - '0';
if (*f == 'c' || *f == 's' || *f == 'p' || *f == 'd' || *f == 'i' || *f == 'u' || *f == 'x' || *f == 'X' || *f == '%')
break ;
f++;
}
if (precision > 0)
{
len = precision - ft_strlen(s);
while (len --> 0)
ret += ft_putchar(' ');
}
ret += ft_puts(s);
return (ret);
}