-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strncmp.c
More file actions
52 lines (44 loc) · 1.51 KB
/
ft_strncmp.c
File metadata and controls
52 lines (44 loc) · 1.51 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marvin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/19 18:56:37 by marvin #+# #+# */
/* Updated: 2022/05/19 18:57:00 by marvin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *str1, const char *str2, size_t n)
{
size_t i;
i = 0;
if (n == 0)
return (0);
while (i < (n - 1) && str1[i] && str2[i] && str1[i] == str2[i])
i++;
return ((unsigned char)str1[i] - (unsigned char)str2[i]);
}
/*int main()
{
char str1[15];
char str2[15];
int ret;
strcpy(str1, "abc4defff");
strcpy(str2, "abcdef");
ret = ft_strncmp(str1, str2, 4);
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);
}*/