-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
30 lines (27 loc) · 1.36 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: gpiccion <gpiccion@student.42wolfsburg. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/21 13:05:21 by gpiccion #+# #+# */
/* Updated: 2021/11/21 13:05:21 by gpiccion ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// Compares the first (at most) 'n' bytes of 's1' and 's2'.
// Returns an int less than, equal to, or greater than zero if 's1' is found,
// respectively, to be less than, to match, or be greater than 's2'.
int ft_strncmp(const char *str1, const char *str2, size_t n)
{
unsigned int i;
i = 0;
while ((str1[i] || str2[i]) && n--)
{
if (str1[i] != str2[i])
return ((unsigned char)str1[i] - (unsigned char)str2[i]);
i++;
}
return (0);
}