-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strncmp.c
33 lines (30 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aelphias <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 17:15:15 by aelphias #+# #+# */
/* Updated: 2019/09/28 21:14:43 by aelphias ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
const unsigned char *ss1;
const unsigned char *ss2;
i = 0;
ss1 = (unsigned char *)s1;
ss2 = (unsigned char *)s2;
while (i < n && ss1[i] != '\0' && ss2[i] != '\0')
{
if (ss1[i] != ss2[i])
return (ss1[i] - ss2[i]);
i++;
}
if (ss1[i] != ss2[i] && i != n)
return (ss1[i] - ss2[i]);
return (0);
}