-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strncmp.c
50 lines (42 loc) · 1.47 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/12 17:26:26 by julmuntz #+# #+# */
/* Updated: 2022/06/02 22:20:57 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
unsigned char *str1;
unsigned char *str2;
i = 0;
str1 = (void *)s1;
str2 = (void *)s2;
if (n == 0)
return (0);
while (str1[i] && str1[i] == str2[i] && i < n - 1)
i++;
return (str1[i] - str2[i]);
}
/*
#include <stdio.h>
#include <string.h>
int main(int arc, char **arv)
{
size_t res;
if (arc == 4)
{
res = strncmp(arv[1], arv[2], atoi(arv[3]));
puts("\n- strncmp");
printf("%ld\n", res);
puts("\n- ft_strncmp");
printf("%ld\n", res);
}
}
*/