-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
49 lines (45 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gudaniel <gudaniel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 13:59:46 by gudaniel #+# #+# */
/* Updated: 2024/04/09 13:59:49 by gudaniel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
while (n > 0 && *s1 && *s1 == *s2)
{
s1++;
s2++;
n--;
}
if (n == 0)
return (0);
else
return ((*(unsigned char *)s1 - *(unsigned char *)s2));
}
/* int main()
{
char str1[15] = "Gustavo";
char str2[15] = "Gustavo";
int ret;
ret = ft_strncmp(str1, str2, 5);
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);
} */