53 lines
1.6 KiB
C
53 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_vprintf_string.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
|
|
/* Updated: 2022/04/26 17:43:42 by gbaconni ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#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 flags;
|
|
int precision;
|
|
int len;
|
|
precision = 0;
|
|
flags = 0;
|
|
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);
|
|
}
|