-
Notifications
You must be signed in to change notification settings - Fork 0
/
more_string.c
123 lines (108 loc) · 1.92 KB
/
more_string.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
#include "shs.h"
/**
* _strcat - Concatenate two strings.
*
* @dest: Destination string.
* @src: Source string.
*
* Return: Pointer to the destination string.
*/
char *_strcat(char *dest, const char *src)
{
int i;
int j;
for (i = 0; dest[i] != '\0'; i++)
;
for (j = 0; src[j] != '\0'; j++)
{
dest[i] = src[j];
i++;
}
dest[i] = '\0';
return (dest);
}
/**
* _strcpy - Copy the string pointed to by src.
*
* @dest: Destination string.
* @src: Source string.
*
* Return: Pointer to the destination string.
*/
char *_strcpy(char *dest, const char *src)
{
size_t a;
for (a = 0; src[a] != '\0'; a++)
{
dest[a] = src[a];
}
dest[a] = '\0';
return (dest);
}
/**
* _strcmp - Compare two strings.
*
* @s1: First string.
* @s2: Second string.
*
* Return: Negative value if s1 is less than s2,
* positive value if s1 is greater than s2, 0 if s1 is equal to s2.
*/
int _strcmp(const char *s1, const char *s2)
{
int i;
for (i = 0; s1[i] == s2[i] && s1[i] != '\0'; i++)
;
if (s1[i] > s2[i])
return (1);
if (s1[i] < s2[i])
return (-1);
return (0);
}
/**
* _strchr - Locate a character in a string.
*
* @s: String to search in.
* @c: Character to locate.
*
* Return: Pointer to the first occurrence of the character c in the string s,
* or NULL if the character is not found.
*/
char *_strchr(const char *s, int c)
{
unsigned int i = 0;
for (; s[i] != '\0'; i++)
if (s[i] == c)
return ((char *)(s + i));
if (s[i] == c)
return ((char *)(s + i));
return (NULL);
}
/**
* _strspn - Get the length of a prefix substring.
*
* @s: Initial segment.
* @accept: Accepted bytes.
*
* Return: Number of accepted bytes.
*/
size_t _strspn(const char *s, const char *accept)
{
size_t i, j;
int bool;
for (i = 0; s[i] != '\0'; i++)
{
bool = 1;
for (j = 0; accept[j] != '\0'; j++)
{
if (s[i] == accept[j])
{
bool = 0;
break;
}
}
if (bool == 1)
break;
}
return (i);
}