-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.c
61 lines (55 loc) · 946 Bytes
/
helpers.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
#include "ssh.h"
/**
* prt_stdo - Print simple string with write in the stdo.
* @str: String to print.
*/
void prt_stdo(char *str)
{
unsigned int s_len;
s_len = _strlen(str);
write(STDOUT_FILENO, str, s_len);
}
/**
* prt_stde - Print simple string with write in the stde.
* @str: String to print.
*/
void prt_stde(char *str)
{
unsigned int s_len;
s_len = _strlen(str);
write(STDERR_FILENO, str, s_len);
}
/**
* _atoi - Find and print the first number
* @s: String to convert to int
* Return: int
*/
int _atoi(char *s)
{
int i, n, c;
i = n = c = 0;
while (*(s + i) != '\0')
{
if (*(s + i) == '-')
c++;
if (*(s + i) >= '0' && *(s + i) <= '9')
{
while (*(s + i) >= '0' && *(s + i) <= '9')
{
if (n == 0)
{
n = (n * 10) + (*(s + i) - '0');
n *= -1;
}
else
n = (n * 10) - (*(s + i) - '0');
i++;
}
if (c % 2 == 0)
n *= -1;
return (n);
}
i++;
}
return (0);
}