-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathft_strncmp.c
More file actions
32 lines (29 loc) · 1.16 KB
/
ft_strncmp.c
File metadata and controls
32 lines (29 loc) · 1.16 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wbeets <wbeets@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/03/20 11:57:18 by wbeets #+# #+# */
/* Updated: 2015/03/20 11:57:18 by wbeets ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int re;
re = 0;
if (n == 0)
return (0);
while (!(re = *(unsigned char *)s1 - *(unsigned char *)s2) && *s2 && --n)
{
++s1;
++s2;
}
if (re < 0)
re = -1;
else if (re > 0)
re = 1;
return (re);
}