-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.c
75 lines (67 loc) · 1.28 KB
/
print.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "shell.h"
/**
* perr_str - a function that checks the errors in a string
* @s1: the first string to be checked
* @s2: the second string to be checked
* Return: 0
*/
int perr_str(char *s1, char *s2)
{
int count = 0;
while (*s1)
count += perr_ch(*s1++);
while (*s2)
count += perr_ch(*s2++);
return (count);
}
/**
* perr_ch - a function that checks for an error in a character in a string
* @c: the character to be checked
* Return: 0
*/
int perr_ch(char c)
{
static char buff[BUFF_SIZE];
static int i;
if (c == -1 || i == (BUFF_SIZE - 1))
{
write(STDERR_FILENO, &buff, i);
i = 0;
}
if (c != -1)
buff[i++] = c;
return (1);
}
/**
* p_str - a function that checks the errors in a string
* @s1: the first string to be checked
* @s2: the second string to be checked
* Return: 0
*/
int p_str(char *s1, char *s2)
{
int count = 0;
while (*s1)
count += p_ch(*s1++);
while (*s2)
count += p_ch(*s2++);
return (count);
}
/**
* p_ch - a function that checks for an error in a character in a string
* @c: the character to be checked
* Return: 0
*/
int p_ch(char c)
{
static char buff[BUFF_SIZE];
static int i;
if (c == -1 || i == (BUFF_SIZE - 1))
{
write(STDOUT_FILENO, &buff, i);
i = 0;
}
if (c != -1)
buff[i++] = c;
return (1);
}