-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strncmp.c
60 lines (54 loc) · 1.86 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
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:04:38 by tpouget #+# #+# */
/* Updated: 2020/05/14 17:06:12 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *l, const char *r, size_t n)
{
size_t i;
int diff;
unsigned char *s1;
unsigned char *s2;
i = 0;
diff = 0;
s1 = (unsigned char*)l;
s2 = (unsigned char*)r;
while (i < n)
{
if ((diff = s1[i] - s2[i]))
return (diff);
if (!s1[i] || !s2[i])
return (diff);
i++;
}
return (diff);
}
/*
#include <string.h>
#include <stdio.h>
int main(int argc, char** argv)
{
char* a1 = argv[1];
char* a2 = argv[2];
printf("string.h output :\n");
printf("Result : %d\n",strncmp(a1, a2, 0));
printf("Result : %d\n",strncmp(a1, a2, 1));
printf("Result : %d\n",strncmp(a1, a2, 2));
printf("Result : %d\n",strncmp(a1, a2, 3));
printf("Result : %d\n",strncmp(a1, a2, 4));
printf("My output :\n");
printf("Result : %d\n",ft_strncmp(a1, a2, 0));
printf("Result : %d\n",ft_strncmp(a1, a2, 1));
printf("Result : %d\n",ft_strncmp(a1, a2, 2));
printf("Result : %d\n",ft_strncmp(a1, a2, 3));
printf("Result : %d\n",ft_strncmp(a1, a2, 4));
return 0;
}
*/