Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions _printf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include "main.h"

/**
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef MAIN_H
#define MAIN_H

#include <stdarg.h>

int _printf(const char *format, ...);
Expand Down
4 changes: 3 additions & 1 deletion print_literals.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <unistd.h>
#include "main.h"
#include <stdlib.h>

/**
* print_char - prints char
Expand Down Expand Up @@ -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);
Expand Down