-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncmp.c
48 lines (42 loc) · 1.4 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
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strncmp.c :+: :+: */
/* +:+ */
/* By: arommers <arommers@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/10/12 14:06:55 by arommers #+# #+# */
/* Updated: 2023/10/30 10:55:39 by arommers ######## odam.nl */
/* */
/* ************************************************************************** */
#include "../include/libft.h"
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 ((unsigned char)s1[i] - (unsigned char)s2[i]);
i++;
}
else
i++;
if (!s1)
return (0);
}
return (0);
}
// int main(void)
// {
// char *str1;
// char *str2;
// size_t i;
// str1 = "bulbasaur";
// str2 = "bulba";
// i = 8;
// printf("%d\n", ft_strncmp(str1, str2, i));
// printf("%d\n", strncmp(str1, str2, i));
// return (0);
// }