-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
31 lines (28 loc) · 1.16 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: msubtil- <msubtil-@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/06 20:09:00 by msubtil- #+# #+# */
/* Updated: 2022/04/26 14:45:53 by msubtil- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
t_uchar *ptr1;
t_uchar *ptr2;
ptr1 = (t_uchar *) s1;
ptr2 = (t_uchar *) s2;
while (*ptr1 && *ptr2 && *ptr1 == *ptr2 && n)
{
ptr1++;
ptr2++;
n--;
}
if (n == 0)
return (0);
return (*ptr1 - *ptr2);
}