Dakha

_putchar.c

Jul 23rd, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include "main.h"
  2.  
  3. /**
  4.  * _puts - function that prints a string with newline.
  5.  * @str: string of characters to print.
  6.  *
  7.  * Return: length of the string of characters.
  8.  */
  9. int _puts(char *str)
  10. {
  11.     char *a = str;
  12.  
  13.     while (*str)
  14.         _putchar(*str++);
  15.     return (str - a);
  16. }
  17.  
  18. /**
  19.  * _putchar - function that writes the character c to stdout
  20.  * @c: The character to print.
  21.  *
  22.  * Return: on success 1,
  23.  * on error, -1 is returned, and error is set appropriately.
  24.  */
  25. int _putchar(int c)
  26. {
  27.     static int i;
  28.     static char buf[1024];
  29.  
  30.     if (c == -1 || i >= 1024)
  31.     {
  32.         write(1, buf, i);
  33.         i = 0;
  34.     }
  35.     if (c != -1)
  36.         buf[i++] = c;
  37.     return (1);
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment