Repository navigation
Expand file tree
/
Copy path_string.c
More file actions
83 lines (69 loc) · 1.41 KB
/
Copy path_string.c
File metadata and controls
83 lines (69 loc) · 1.41 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
#include "_string.h"
/**
* _n_chars - count number of occurances of char in string
* @str: string
* @char_: character
* Return: number of occurances (short int)
*/
short int _n_chars(char *str, char char_)
{
short int n;
if (!(*str))
return (0);
n = *str == char_ ? 1 : 0;
return (n + _n_chars(++str, char_));
}
/**
* _strcat - append one string to another
* @dest: left operand being added to
* @src: right operand
*
* Return: Pointer to @dest (char *)
*/
char *_strcat(char *dest, char *src)
{
char *root = dest;
while (*dest != '\0')
dest++;
while (*src != '\0')
{
*dest++ = *src++;
}
*dest = *src;
dest = root;
return (dest);
}
/**
* _strlen - get the length of a string
* @s: string in question
* Return: Always 0.
*/
int _strlen(char *s)
{
short int i = 0;
while (*s++ != '\0')
i++;
return (i);
}
/**
* _strcmp - compare two strings
* @s1: left operand
* @s2: right operand
* Description: Compares two strings, returning
* - zero if the strings are the same
* - a negative value if s1 comes before s2,
* lexicographically
* - a positive value if s1 comws after s2,
* lexicographically
* Return: if equal -> 0 else -> integral difference
* between the first differing chars
*/
int _strcmp(char *s1, char *s2)
{
const int len = _strlen(s1);
int iter = 0;
for (; iter <= len; iter++)
if (s1[iter] != s2[iter])
return (s1[iter] - s2[iter]);
return (0);
}