Dakha

_printf.c

Jul 23rd, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include "main.h"
  2.  
  3. /**
  4.  * _printf - function that produces output according,
  5.  * to a format.
  6.  * @format: the format string.
  7.  *
  8.  * Return: number of bytes printed.
  9.  */
  10. int _printf(const char *format, ...)
  11. {
  12.     int sum = 0;
  13.     va_list ap;
  14.     char *p, *start;
  15.  
  16.     va_start(ap, format);
  17.  
  18.     if (!format || (format[0] == '%' && !format[1]))
  19.         return (-1);
  20.     if (format[0] == '%' && format[1] == ' ' && !format[2])
  21.         return (-1);
  22.  
  23.     for (p = (char *)format; *p; p++)
  24.     {
  25.         if (*p != '%')
  26.         {
  27.             sum += _putchar(*p);
  28.             continue;
  29.         }
  30.         start = p;
  31.         p++;
  32.         if (!get_specifier(p))
  33.             sum += print_from_to(start, p, 0);
  34.         else
  35.             sum += get_print_func(p, ap);
  36.     }
  37.     _putchar(-1);
  38.     va_end(ap);
  39.     return (sum);
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment