From 5a789d2a3f720506dc5d60f522cee52724046b91 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 14 Sep 2020 16:42:37 +0200 Subject: Added %c format for errorf --- src/error.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/error.c b/src/error.c index 2e56117..7da14d5 100644 --- a/src/error.c +++ b/src/error.c @@ -6,14 +6,14 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 11:02:52 by charles #+# #+# */ -/* Updated: 2020/09/10 20:29:41 by charles ### ########.fr */ +/* Updated: 2020/09/14 16:42:01 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "eval.h" /* -** \brief printf like function that only works with `%s`, +** \brief printf like function that only works with `%s` and `%c`, ** prefix the message with the program name ** and output on STDERR ** \note NULL arguments are ignored @@ -34,7 +34,8 @@ void errorf(const char *format, ...) void verrorf(const char *format, va_list ap) { - char *arg; + char *str; + char c; ft_putstr_fd(g_basename, STDERR_FILENO); ft_putstr_fd(": ", STDERR_FILENO); @@ -42,8 +43,14 @@ void verrorf(const char *format, va_list ap) { if (format[0] == '%' && format[1] == 's') { - arg = va_arg(ap, char*); - ft_putstr_fd(arg, STDERR_FILENO); + str = va_arg(ap, char*); + ft_putstr_fd(str, STDERR_FILENO); + format += 2; + } + else if (format[0] == '%' && format[1] == 'c') + { + c = va_arg(ap, int); + ft_putchar_fd(c, STDERR_FILENO); format += 2; } else -- cgit