-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
29 lines (26 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: isb3 <isb3@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/19 14:27:47 by adesille #+# #+# */
/* Updated: 2023/11/06 14:25:33 by isb3 ### ########.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)
{
if (str1[i] != str2[i])
return ((unsigned char)str1[i] - (unsigned char)str2[i]);
i++;
}
if (i == n)
return (0);
return ((unsigned char)str1[i] - (unsigned char)str2[i]);
}