-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strncmp.c
More file actions
49 lines (45 loc) · 1.65 KB
/
Copy pathft_strncmp.c
File metadata and controls
49 lines (45 loc) · 1.65 KB
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
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strncmp.c :+: :+: */
/* +:+ */
/* By: vsudak <vsudak@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/10/16 13:12:32 by vsudak #+# #+# */
/* Updated: 2025/11/02 19:01:43 by vsudak ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
// compare n amount of elements
// and return
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
if (n == 0)
return (0);
while (i < n - 1 && s1[i] == s2[i] && s1[i] && s2[i])
i++;
if ((unsigned char)s1[i] != (unsigned char)s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
return (0);
}
// int ft_strncmp(const char *s1, const char *s2, size_t n)
// {
// size_t i;
// i = 0;
// while(i < n && s1[i] && s2[i])
// {
// if (s1[i] != s2[i])
// return (s1[i] - s2[i]);
// i++;
// }
// return (0);
// }
// int main()
// {
// char ss[] = "zyxbcdefgh";
// char dd[] = "abcdwxyz";
// printf("%d\n", ft_strncmp("test\200", "test\0", 6));
// printf("%d\n", strncmp("test\200", "test\0", 6));
// }