-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_strncmp.c
34 lines (31 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abello-r <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/07 19:39:58 by abello-r #+# #+# */
/* Updated: 2020/01/24 14:59:31 by abello-r ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
unsigned char *ss1;
unsigned char *ss2;
size_t c1;
size_t c2;
ss1 = (unsigned char *)s1;
ss2 = (unsigned char *)s2;
c1 = 0;
c2 = 0;
if (n == 0)
return (c2);
while ((ss1[c1] == ss2[c1] && ss1[c1] != '\0') && c1 < n)
c1++;
if (c1 == n)
c1--;
c2 = ss1[c1] - ss2[c1];
return (c2);
}