-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
28 lines (25 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlins <rlins@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/03 23:56:34 by rlins #+# #+# */
/* Updated: 2022/12/16 08:10:40 by rlins ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *str1, const char *str2, size_t n)
{
size_t i;
int diff;
if (n == 0)
return (0);
i = 0;
while ((str1[i] == str2[i]) && (str1[i] != '\0') && (str2[i] != '\0')
&& (i < (n - 1)))
i++;
diff = (str1[i] - str2[i]);
return (diff);
}