2022-04-13 08:01:46 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* ft_vprintf_string.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
|
2022-04-29 09:12:07 +02:00
|
|
|
/* Updated: 2022/04/29 09:03:47 by gbaconni ### lausanne.ch */
|
2022-04-13 08:01:46 +02:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "libftprintf.h"
|
|
|
|
|
|
|
|
|
|
int ft_vprintf_string(const char *format, va_list ap)
|
|
|
|
|
{
|
2022-04-26 17:53:39 +02:00
|
|
|
int ret;
|
|
|
|
|
char *s;
|
2022-04-13 08:01:46 +02:00
|
|
|
|
|
|
|
|
(void) format;
|
2022-04-25 07:14:14 +02:00
|
|
|
ret = 0;
|
2022-04-13 08:01:46 +02:00
|
|
|
s = va_arg(ap, char *);
|
2022-04-25 07:14:14 +02:00
|
|
|
if (s == NULL)
|
|
|
|
|
{
|
|
|
|
|
ret = ft_puts("(null)");
|
|
|
|
|
return (ret);
|
|
|
|
|
}
|
2022-04-26 17:53:39 +02:00
|
|
|
|
|
|
|
|
const char *f;
|
|
|
|
|
int precision;
|
|
|
|
|
int len;
|
2022-04-26 19:23:00 +02:00
|
|
|
int flags;
|
2022-04-26 17:53:39 +02:00
|
|
|
precision = 0;
|
2022-04-26 19:23:00 +02:00
|
|
|
flags = ft_vprintf_flags_bonus(format, ap);
|
|
|
|
|
(void) flags;
|
2022-04-26 17:53:39 +02:00
|
|
|
f = format;
|
|
|
|
|
while (*f != '\0')
|
|
|
|
|
{
|
2022-04-29 08:46:53 +02:00
|
|
|
if (ft_isdigit(*f))
|
2022-04-26 17:53:39 +02:00
|
|
|
precision = precision * 10 + *f - '0';
|
2022-04-29 09:12:07 +02:00
|
|
|
if (ft_strchr(SPECIFIERS, *f) != NULL)
|
2022-04-26 17:53:39 +02:00
|
|
|
break ;
|
|
|
|
|
f++;
|
|
|
|
|
}
|
|
|
|
|
if (precision > 0)
|
|
|
|
|
{
|
|
|
|
|
len = precision - ft_strlen(s);
|
2022-04-29 09:12:07 +02:00
|
|
|
while (len-- > 0)
|
2022-04-26 17:53:39 +02:00
|
|
|
ret += ft_putchar(' ');
|
|
|
|
|
}
|
|
|
|
|
ret += ft_puts(s);
|
2022-04-13 08:01:46 +02:00
|
|
|
return (ret);
|
|
|
|
|
}
|