-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strncmp.c
44 lines (40 loc) · 1.45 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: samoore <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 12:41:40 by samoore #+# #+# */
/* Updated: 2023/11/13 15:30:45 by samoore ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
if (n == 0)
return (0);
i = 0;
while (s1[i] == s2[i] && i < n)
i++;
if (i == n)
return (0);
return (s1[i] - s2[i]);
}
/*int main (void)
{
char a1[10] = "ABCD";
char a2[10] = "ABC";
char b1[10] = "ABC";
char b2[10] = "ABCD";
char c1[10] = "";
char c2[10] = "1243";
int n1 = 2;
int n2 = 4444;
int n3 = 3;
printf("%d %d\n%d %d\n%d %d", strncmp(a1, a2, n1),
ft_strncmp(a1, a2, n1), strncmp(b1, b2, n2),
ft_strncmp(b1, b2, n2), strncmp(c1, c2, n3), ft_strncmp(c1, c2, n3));
}
*/