-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
executable file
·30 lines (27 loc) · 1.16 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shillebr <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/22 07:23:38 by shillebr #+# #+# */
/* Updated: 2018/05/31 14:13:09 by shillebr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *str1, const char *str2, size_t n)
{
size_t i;
i = 0;
while (str1[i] && str2[i] && i < n - 1)
{
if (str1[i] == str2[i])
i++;
else
break ;
}
if (n > 0)
return ((unsigned char)str1[i] - (unsigned char)str2[i]);
return (0);
}