-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
51 lines (47 loc) · 1.64 KB
/
ft_strncmp.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgerdzhi <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/29 16:53:11 by rgerdzhi #+# #+# */
/* Updated: 2024/07/08 17:58:59 by rgerdzhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t c;
c = 0;
if (n == 0)
return (0);
while (s1[c] == s2[c] && s1[c] != '\0' && s2[c] != '\0' && c < (n - 1))
{
c++;
}
return ((unsigned char )s1[c] - (unsigned char )s2[c]);
}
/*
int main ()
{
char str1[15] = "Raya2111111";
char str2[15] = "NULL";
int ret;
ret = strncmp(str1, str2, -1);
if (ret < 0)
printf("str1 is less than str2\n");
else if(ret > 0)
printf("str2 is less than str1\n");
else
printf("str1 is equal to str2\n");
ret = ft_strncmp(str1, str2, -1);
if(ret < 0)
printf("str1 is less than str2");
else if(ret > 0)
printf("str2 is less than str1");
else
printf("str1 is equal to str2");
return(0);
}
*/