-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxstrcmp.c
109 lines (95 loc) · 1.93 KB
/
xstrcmp.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
#include "main.h"
/**
* _strcmp - Compares pointers to two strings.
* @s1: A pointer to the first string to be compared.
* @s2: A pointer to the second string to be compared.
*
* Return: If str1 < str2, the negative difference of
* the first unmatched characters.
* If s1 == s2, 0.
* If s1 > s2, the positive difference of
* the first unmatched characters.
*/
int _strcmp(char *s1, char *s2)
{
while ((*s1 && *s2) && (*s1 == *s2))
{
s1++;
s2++;
}
return (*s1 - *s2);
}
/**
* _strcpy - copie a string from source to destination
* @source: the string source
* @dest: the string destination
*
* Return: the pointer to dest
*/
char *_strcpy(char *dest, char *source)
{
int i;
for (i = 0; source[i] != '\0'; i++)
{
dest[i] = source[i];
}
dest[i] = '\0';
return (dest);
}
/**
* _isalpha - check if the input is a letter
* @c: the character to be checked
*
* Return: 1 if letter, 0 otherwise
*/
int _isalpha(int c)
{
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
{
return (SUCCESS);
}
return (FAIL);
}
/**
* _strcat - concatenates two string in a path form
* @first: the first given destination
* @second: the second given source
*
* Return: (Success) to the newly string
* ------- (Fail) if it failed
*/
char *_strcat(char *first, char *second)
{
int len1, len2, i = 0, j = 0;
char *result;
len1 = _strlen(first);
len2 = _strlen(second);
result = malloc((len1 + len2 + 2) * sizeof(char));
if (!result)
return (NULL);
*result = '\0';
while (first[j])
result[i++] = first[j++];
result[i++] = '/';
j = 0;
while (second[j])
result[i++] = second[j++];
result[i] = '\0';
return (result);
}
/**
* _strlen - finds the length of a given string
* @str: the given string
*
* Return: (Success) the length of the string
* ------- (Fail) negative value
*/
int _strlen(char *str)
{
char *ptr;
if (str == NULL)
return (-1);
for (ptr = str; *ptr; ptr++)
;
return (ptr - str);
}