-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_strncmp.c
32 lines (29 loc) · 1.21 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
32
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marsoare <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/12 16:59:14 by marsoare #+# #+# */
/* Updated: 2024/04/19 13:41:02 by marsoare ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* Look at strcmp
*/
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t j;
j = 0;
while (s1[j] == s2[j] && s1[j] && j < n)
{
if (s1[j] != s2[j])
return ((unsigned char)s1[j] - (unsigned char)s2[j]);
j++;
}
if (j < n)
return ((unsigned char)s1[j] - (unsigned char)s2[j]);
return (0);
}