You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
3 years ago
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_printf.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2021/10/27 08:09:49 by narnaud #+# #+# */
|
||
|
/* Updated: 2021/11/17 09:40:16 by narnaud ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "./libft/libft.h"
|
||
|
#include "ft_printf.h"
|
||
|
|
||
|
int ft_printf(const char *str, ...)
|
||
|
{
|
||
|
va_list args;
|
||
|
size_t n;
|
||
|
size_t i;
|
||
|
const char *g_types = {"cspdiuxX%"};
|
||
|
static int (*g_printf_fcts[9])(va_list arg, const char *str) = {\
|
||
|
va_putchar, va_putstr, va_putptr, va_putnbr, va_putnbr, va_putunsign, \
|
||
|
va_putx, va_putx_cap, va_putperc};
|
||
|
|
||
|
i = 0;
|
||
|
va_start (args, str);
|
||
|
while (*str)
|
||
|
{
|
||
|
n = -1;
|
||
|
if ((*str == '%' && str++) || !(++i && ft_putchar((int)*str)))
|
||
|
while (++n < 9)
|
||
|
if (g_types[n] == *str)
|
||
|
i += (g_printf_fcts[n])(args, str);
|
||
|
str++;
|
||
|
}
|
||
|
va_end(args);
|
||
|
return (i);
|
||
|
}
|