-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strncmp.c
41 lines (38 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/16 19:51:56 by ibeliaie #+# #+# */
/* Updated: 2023/05/23 14:46:02 by ibeliaie ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* compare 2 strings */
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
if (n == 0)
return (0);
while (n > 1 && *s1 && *s1 == *s2)
{
s1++;
s2++;
n--;
}
return (*(unsigned char *)s1 - *(unsigned char *)s2);
}
// int main() {
// char str1[] = "A noisy noise annoys an oyster most.";
// char str2[] = "bonjour";
// int result = ft_strncmp(str1, str2, 4);
// if (result < 0) {
// printf("str1 is less than str2\n");
// } else if (result > 0) {
// printf("str1 is greater than str2\n");
// } else {
// printf("str1 is equal to str2\n");
// }
// return (0);
// }