-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.c
More file actions
40 lines (34 loc) · 655 Bytes
/
string.c
File metadata and controls
40 lines (34 loc) · 655 Bytes
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
#include "shell.h"
/**
* my_strlen - A function to return the length of a string
* @str: the string length to check
*
* Return: integer length of string
*/
int my_strlen(const char *str)
{
int len = 0;
while (str[len] != '\0')
{
len++;
}
return (len);
}
/**
* my_strcmp - A function to compare two null terminated strings
* @str1: first string
* @str2: second string
* Return: Zero if str1 == str2, positive if str1 > str2,
* Negative if str1 < str2
*/
int my_strcmp(const char *str1, const char *str2)
{
while (*str1 && *str2)
{
if (*str1 != *str2)
return (*str1 - *str2);
str1++;
str2++;
}
return (*str1 - *str2);
}