-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
31 lines (28 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lgasc <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/03 17:13:45 by lgasc #+# #+# */
/* Updated: 2023/02/17 13:32:06 by lgasc ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/** @remark This function aims to replicate the `libc` function `strncmp`. */
int ft_strncmp(const char *string1, const char *string2, size_t n)
{
unsigned int i;
i = 0;
while (i < n)
{
if (string1[i] != string2[i])
return ((const unsigned char) string1[i]
- (const unsigned char) string2[i]);
if (string1[i] == '\0')
return (0);
i++;
}
return (0);
}