-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
133 lines (111 loc) · 1.8 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "crikey.h"
/**
* _print - prints a string
* @src: The string to be printed
*
* Return: Number of characters printed
*/
int _print(char *src)
{
int len, ret;
for (len = 0; src[len]; ++len)
;
ret = write(STDOUT_FILENO, src, len);
if (ret != len)
{
write(STDERR_FILENO, "Error writing\n", 14);
exit(71);
}
return (ret);
}
/**
* _print_s - prints a string to the standard output
* @src: first part of a string
* @end: second part of a string
*
* Return: 1 for match, 0 for not a match
*/
int _print_s(char *src, char *end)
{
int len, tot = 0;
int ret;
for (len = 0; src[len]; ++len)
;
tot += len;
ret = write(STDOUT_FILENO, src, len);
for (len = 0; end[len]; ++len)
;
tot += len;
ret += write(STDOUT_FILENO, end, len);
ret += write(STDOUT_FILENO, "\n", 1);
tot += 1;
if (ret != tot)
{
write(STDERR_FILENO, "Error writing\n", 14);
exit(71);
}
return (ret);
}
/**
* _strcmp - compares two strings
* @s1: First string
* @s2: Second string
*
* Return: 1 for match, 0 for not a match
*/
int _strcmp(char *s1, char *s2)
{
for (; *s1 && *s2; ++s1, ++s2)
{
if (*s1 != *s2)
return (0);
}
if (*s1 != *s2)
return (0);
return (1);
}
/**
* _atoi - Converts a string to an integer
* @s: pointer to the first character of the string
*
* Return: Value of integer in string
*/
int _atoi(char *s)
{
unsigned int num;
int neg;
neg = 1;
num = 0;
for (; *s; s++)
{
if (*s >= '0' && *s <= '9')
{
num *= 10;
num += *s - '0';
}
else if (num > 0)
{
break;
}
else if (*s == '-')
{
neg = -neg;
}
}
return (num * neg);
}
/**
* replaceTabs - replaces tabs to spaces
* @src: Pointer to the string to manipulate
*/
void replaceTabs(char *src)
{
int i;
for (i = 0; src[i]; i++)
{
if (src[i] == '\t')
{
*(src + i) = ' ';
}
}
}