-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strncmp.c
More file actions
38 lines (34 loc) · 1.6 KB
/
ft_strncmp.c
File metadata and controls
38 lines (34 loc) · 1.6 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ccarnot <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/05 13:59:07 by ccarnot #+# #+# */
/* Updated: 2023/05/11 12:11:52 by ccarnot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*******************************************
* Function: strncmp
* Library: <string.h>
* Description: compares at most n bytes of two strings s1 and s2.
* Memory allocations: None
* Crash values:
* - n != 0 AND {s1 or/and s2 is NULL}
* Return value:
* - an integer less than, equal to, or greater than zero if the first n characters of the strings are found to be less than, equal to, or greater than each other, respectively.
*******************************************/
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] || s1[i] < s2[i])
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
i++;
}
return (0);
}