-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
42 lines (38 loc) · 1.39 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
33
34
35
36
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sizerese <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/07 19:55:39 by sizerese #+# #+# */
/* Updated: 2023/07/30 21:58:24 by sizerese ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *src, const char *dest, size_t n)
{
size_t i;
unsigned char *src1;
unsigned char *dest1;
i = 0;
src1 = (unsigned char *)src;
dest1 = (unsigned char *)dest;
while (src1[i] && i < n)
{
if (src1[i] != dest1[i])
return (src1[i] - dest1[i]);
i++;
}
if (i != n)
return (src1[i] - dest1[i]);
return (0);
}
/*
int main(){
char src[] = "hell0";
char des[] = "hell2";
printf("%d\n", ft_strncmp(src, des, 5));
printf("%d\n", strncmp(src, des, 5));
}
*/