-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strncmp.c
57 lines (54 loc) · 1.63 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abaudot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/05 15:04:56 by abaudot #+# #+# */
/* Updated: 2021/01/05 15:05:11 by abaudot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
**int ft_strncmp(const char *s1, const char *s2, size_t n)
**{
** t_op *a1;
** t_op *a2;
**
** if (!n)
** return (0);
** if (n >= OPSIZ)
** {
** a1 = (t_op *)s1;
** a2 = (t_op *)s2;
** while (n >= OPSIZ && *a1 == *a2)
** {
** n -= OPSIZ;
** if (!n || ((*a1 - LOMAGIC) & ~(*a1) & HIMAGIC))
** return (0);
** a1++;
** a2++;
** }
** s1 = (const char *)a1;
** s2 = (const char *)a2;
** }
** while (n-- && *s1 == *s2++)
** if (!n || !*s1++)
** return (0);
** return ((unsigned char)*s1 - (unsigned char)*(--s2));
**}
*/
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
if (!n)
return (0);
while (*s1 == *s2)
{
if (!--n || !*s1)
return (0);
++s1;
++s2;
}
return (*(unsigned char*)s1 - *(unsigned char*)s2);
}