diff --git a/_printf.c b/_printf.c index 86177f3..7817ecc 100644 --- a/_printf.c +++ b/_printf.c @@ -1,5 +1,5 @@ #include -#include +#include #include "main.h" /** @@ -18,6 +18,8 @@ int _printf(const char *format, ...) if (!(*format)) write(1, "User input is needed", 21); + if (format == NULL) + print_error("Cannot enter NULL as printf format string"); while (*format) { @@ -33,10 +35,10 @@ int _printf(const char *format, ...) } /** - * p_func - executes print function - * @ap: Variadic arguments - * @specifier: Format type pointer - * + * p_func - Auxilliary Function + * Description: It calls other print functions based on the specifier + * @ap: Argument Pointer + * @specifier: Format Specifier Character * Return: Number of chars printed */ int p_func(va_list ap, char specifier) @@ -54,6 +56,10 @@ int p_func(va_list ap, char specifier) case '%': char_count += write(1, "%", 1); break; + case '\0': + print_error("Invalid Format"); + exit(1); + break; } return (char_count); diff --git a/main.h b/main.h index 4d68fee..4e6d399 100644 --- a/main.h +++ b/main.h @@ -1,5 +1,6 @@ #ifndef MAIN_H #define MAIN_H + #include int _printf(const char *format, ...); diff --git a/print_literals.c b/print_literals.c index 4970d60..4bff395 100644 --- a/print_literals.c +++ b/print_literals.c @@ -1,5 +1,6 @@ #include #include "main.h" +#include /** * print_char - prints char @@ -28,7 +29,8 @@ int print_string(va_list ap) char *str = va_arg(ap, char *); if (str == NULL) - str = "(nil)"; + print_error("Cannot enter NULL as printf format string"); + return (0); while (*str) { char_count += write(1, str, 1);