-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmore_strfunctions.c
More file actions
65 lines (61 loc) · 871 Bytes
/
more_strfunctions.c
File metadata and controls
65 lines (61 loc) · 871 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "holberton.h"
/**
* *_strchr - find and cut
* @s: array in
* @c: char to search
* Return: Always 0.
*/
char *_strchr(char *s, char c)
{
int j = 0;
while (2)
{
if (s[j] == c)
return (s + j);
if (s[j] == '\0')
return (NULL);
j++;
}
}
/**
* _atoi - converts string to number
* @s : pointer int
*
* _atoi: converts string to number
*
* Return: int
*/
int _atoi(char *s)
{
int i;
int check_num;
unsigned int sum;
unsigned int x;
int neg;
neg = 0;
check_num = 0;
sum = 0;
i = 0;
while (s[i] != '\0')
{
if ((s[i] > '9' || s[i] < '0') && check_num > 0)
break;
if (s[i] == '-')
neg++;
if (s[i] >= '0' && s[i] <= '9')
check_num++;
i++;
}
i = i - 1;
x = 1;
while (check_num > 0)
{
sum = sum + ((s[i] - '0') * x);
x = x * 10;
i--;
check_num--;
}
if (neg % 2 != 0)
sum = sum * -1;
return (sum);
}