From 62afe606a355581c5b48cca361478c43fb6ae4cf Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 19 Apr 2020 22:27:11 +0200 Subject: Well well well that wasn't too bad, now remake everything --- libft/src/ft_printf.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 libft/src/ft_printf.c (limited to 'libft/src/ft_printf.c') diff --git a/libft/src/ft_printf.c b/libft/src/ft_printf.c new file mode 100644 index 0000000..ec1922f --- /dev/null +++ b/libft/src/ft_printf.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include + +static int + ft_printf_return(t_printflist *pflist) +{ + int ret; + + ret = write(1, pflist->output, pflist->fulllen); + ft_memdel((void**)&pflist->output); + ft_memdel((void**)&pflist->fullflag); + ft_memdel((void**)&pflist); + return (ret); +} + +int + ft_printf(const char *format, ...) +{ + t_printflist *pflist; + va_list arg; + int pos; + + if (!format) + return (-1); + if ((pos = ft_strlchr(format, '%')) < 0) + return (ft_putstr(format)); + else + { + pflist = ft_printf_init_struct(format); + ft_printf_putpart(format, 0, pos, pflist); + va_start(arg, format); + while (pos >= 0) + { + pos = ft_printf_flags(format, pos, arg, pflist); + ft_printf_reinit_struct(pflist); + } + va_end(arg); + return (ft_printf_return(pflist)); + } + return (0); +} -- cgit v1.2.3