-
Notifications
You must be signed in to change notification settings - Fork 0
/
aux_str.c
executable file
·106 lines (95 loc) · 1.74 KB
/
aux_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
#include "main.h"
/**
* _strcat - concatenate two strings
* @dest: char pointer the dest of the copied str
* @src: const char pointer the source of str
* Return: the dest
*/
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 - Copies the string pointed to by src.
* @dest: Type char pointer the dest of the copied str
* @src: Type char pointer the source of str
* Return: the dest.
*/
char *_strcpy(char *dest, char *src)
{
size_t a;
for (a = 0; src[a] != '\0'; a++)
{
dest[a] = src[a];
}
dest[a] = '\0';
return (dest);
}
/**
* _strcmp - Function that compares two strings.
* @s1: type str compared
* @s2: type str compared
* Return: Always 0.
*/
int _strcmp(char *s1, char *s2)
{
int i;
for (i = 0; s1[i] == s2[i] && s1[i]; i++)
;
if (s1[i] > s2[i])
return (1);
if (s1[i] < s2[i])
return (-1);
return (0);
}
/**
* _strchr - locates a character in a string,
* @s: string.
* @c: character.
* Return: the pointer to the first occurrence of the character c.
*/
char *_strchr(char *s, char c)
{
unsigned int i = 0;
for (; *(s + i) != '\0'; i++)
if (*(s + i) == c)
return (s + i);
if (*(s + i) == c)
return (s + i);
return ('\0');
}
/**
* _strspn - gets the length of a prefix substring.
* @s: initial segment.
* @accept: accepted bytes.
* Return: the number of accepted bytes.
*/
int _strspn(char *s, char *accept)
{
int i, j, 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);
}