-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strncmp.c
35 lines (32 loc) · 1.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aazeroua <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/02 20:15:50 by aazeroua #+# #+# */
/* Updated: 2019/04/21 04:22:40 by aazeroua ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
unsigned char *a;
unsigned char *b;
a = (unsigned char *)s1;
b = (unsigned char *)s2;
if (!n)
return (0);
while (--n && *a && *b)
{
if (*a == *b)
{
a++;
b++;
}
else
return (*a - *b);
}
return (*a - *b);
}