Dakha

specifiers.c

Jul 23rd, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include "main.h"
  2.  
  3. /**
  4.  * get_specifier - function tht finds the format function
  5.  * @s: string of the format.
  6.  *
  7.  * Return: the number of bytes printed.
  8.  */
  9. int (*get_specifier(char *s))(va_list ap)
  10. {
  11.     specifier_t specifiers[] = {
  12.         {"c", print_character},
  13.         {"s", print_string},
  14.         {"%", print_percent},
  15.         {NULL, NULL}
  16.     };
  17.  
  18.     int i = 0;
  19.  
  20.     while (specifiers[i].specifier)
  21.     {
  22.         if (*s == specifiers[i].specifier[0])
  23.         {
  24.             return (specifiers[i].f);
  25.         }
  26.         i++;
  27.     }
  28.     return (NULL);
  29. }
  30.  
  31. /**
  32.  * get_print_func - function finds the format function.
  33.  * @s: string of the format.
  34.  * @ap: argument pointer.
  35.  *
  36.  * Return: pointer function to argumet pointer.
  37.  */
  38. int get_print_func(char *s, va_list ap)
  39. {
  40.     int (*f)(va_list) = get_specifier(s);
  41.  
  42.     if (f)
  43.         return (f(ap));
  44.     return (0);
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment