-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_str.c
124 lines (106 loc) · 1.88 KB
/
helper_str.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
#include "shell.h"
/**
* _memcpy - copies n bytes form the memory area src
* to memory area dest
* @src: source code to copy
* @dest: destination to copy to
* @n: how many bytes to copy
* Return: dest;
*/
char *_memcpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
for (i = 0; i < n; i++)
{
dest[i] = src[i];
}
return (dest);
}
/**
*_memset - sets first n bytes of the memory area
* @s: array to set
* @b: what to set it to
* @n: first n bytes
* Return: s
*/
char *_memset(char *s, char b, unsigned int n)
{
unsigned int i;
for (i = 0; i < n; i++)
{
s[i] = b;
}
return (s);
}
/**
* _strcat - appends strings
* @dest: destination to append
* @src: what to append
* Return: pointer to dest
*/
char *_strcat(char *dest, char *src)
{
int i, j;
for (i = 0; dest[i] != '\0'; i++)
{
}
j = 0;
while (src[j] != '\0')
{
dest[i] = src[j];
j++;
i++;
}
/*i++;*/
dest[i] = '\0';
return (dest);
}
/**
* _strncat - concatenates one string (number of byte given)
* to another
* @dest: where to concatenate
* @src: string to concatenate
* @n: how many bytes to
* Return: dest
*/
char *_strncat(char *dest, char *src, int n)
{
int i, j;
for (i = 0; dest[i] != '\0'; i++)
{
}
j = 0;
while (j < n && src[j] != '\0')
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}
/**
* _strstr - finds the first occurence of the substring needle
* in the string haystack
* @haystack: string to search
* @needle: string to find
* Return: pointer to the beginning of the located substring
*/
char *_strstr(char *haystack, char *needle)
{
while (*haystack != '\0')
{
char *beginning = haystack;
char *pattern = needle;
while (*pattern == *haystack && *pattern != '\0'
&& *haystack != '\0')
{
haystack++;
pattern++;
}
if (*pattern == '\0')
return (beginning);
haystack = beginning + 1;
}
return (NULL);
}