libft/src/ft_printf/ft_printf.c

43 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* ft_printf.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/10/11 14:49:07 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/10/27 16:37:46 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include <stdarg.h>
#include <unistd.h>
#include "libft.h"
#include "ft_printf.h"
int ft_printf(const char *format, ...)
{
int wrote;
int result;
va_list args;
result = 0;
va_start(args, format);
while (*format && result >= 0)
{
if (*format == '%')
wrote = parse_placeholder(&format, args);
else
wrote = write(1, format, 1);
if (wrote < 0)
{
result = wrote;
break ;
}
result += wrote;
format++;
}
va_end(args);
return (result);
}