-
Notifications
You must be signed in to change notification settings - Fork 0
/
strcmp_functions.c
52 lines (47 loc) · 970 Bytes
/
strcmp_functions.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
#include "main.h"
/**
* _strcmp - this function compare two strings
* @s1: the first string of the program
* @s2: the second string of the program
(* a blank line
* Description: this function comparing two strings using the first value)?
(* section header: the header of this function is holberton.h)*
* Return: return a number depends os the resul fo comparation on success.
*/
int _strcmp(char *s1, char *s2)
{
int j;
for (j = 0; s1[j] != '\0' || s2[j] != '\0'; j++)
{
if (s1[j] != s2[j])
{
return (s1[j] - s2[j]);
}
}
return (0);
}
/**
*_strncmp - function that compares two strings.
*@s1: string one of variable
*@s2: string two of the variable
*@n: number of characters
* Return: diference, if executed properly
*/
int _strncmp(const char *s1, const char *s2, size_t n)
{
int i = 0, j = 0;
while (n && s1[i] && (s1[i] == s2[j]))
{
i++;
j++;
n--;
}
if (n == 0)
{
return (0);
}
else
{
return (s1[i] - s2[j]);
}
}