-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil2.c
More file actions
85 lines (77 loc) · 1.46 KB
/
Copy pathutil2.c
File metadata and controls
85 lines (77 loc) · 1.46 KB
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
#include "main.h"
/**
* _atoi - converts string to an integer
* @s: Pointer to character string
*
* Return: returns integer value
*/
int _atoi(char *s)
{
int sign;
unsigned int num;
char *temp;
temp = s;
num = 0;
sign = 1;
while (*temp != '\0' && (*temp < '0' || *temp > '9'))
{
if (*temp == '-')
sign *= -1;
temp++;
}
if (*temp != '\0')
{
do {
num = num * 10 + (*temp - '0');
temp++;
} while (*temp >= '0' && *temp <= '9');
}
return (num * sign);
}
/**
* _strstr - finds the first occurrence of the substring.
* needle in the string haystack.
* @haystack: entire string.
* @needle: substring.
* Return: pointer to the beginning of located substring or
* NULL if the substring is not found.
*/
char *_strstr(char *haystack, char *needle)
{
char *bhaystack;
char *pneedle;
while (*haystack != '\0')
{
bhaystack = haystack;
pneedle = needle;
while (*haystack != '\0' && *pneedle != '\0' && *haystack == *pneedle)
{
haystack++;
pneedle++;
}
if (!*pneedle)
return (bhaystack);
haystack = bhaystack + 1;
}
return (0);
}
/**
*_strcat - Write a function that concatenates two strings.
*
*@dest: This is the output dest
*@src: This is the input source
*
* Return: This return to dest, that concatenates two strings
*/
char *_strcat(char *dest, char *src)
{
int i, j, k;
i = 0, j = 0;
while (dest[i] != '\0')
i++;
while (src[j] != '\0')
j++;
for (k = 0; k <= j; k++, i++)
dest[i] = src[k];
return (dest);
}