-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_writechar.c
More file actions
42 lines (38 loc) · 715 Bytes
/
Copy path_writechar.c
File metadata and controls
42 lines (38 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "main.h"
#include <unistd.h>
/**
* _putchar - writes the character c to stdout
* @c: The character to print
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
* Description: _putchar uses a local buffer of 1024 to call write
* as little as possible
*/
int _putchar(char c)
{
static char buf[1024];
static int i;
if (c == -1 || i >= 1024)
{
write(1, &buf, i);
i = 0;
}
if (c != -1)
{
buf[i] = c;
i++;
}
return (1);
}
/**
* _puts - prints a string to stdout
* @str: pointer to the string to print
* Return: number of chars written
*/
int _puts(char *str)
{
register int i;
for (i = 0; str[i] != '\0'; i++)
_putchar(str[i]);
return (i);
}