-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memcmp.c
39 lines (36 loc) · 1.47 KB
/
ft_memcmp.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rruiz-sa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/23 15:08:15 by rruiz-sa #+# #+# */
/* Updated: 2022/10/13 17:48:31 by rruiz-sa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
char *str1;
char *str2;
if (!s1 && !s2)
return (0);
str1 = (char *)s1;
str2 = (char *)s2;
i = 0;
if (n == 0)
return (0);
while (str1[i] == str2[i] && (i < n - 1))
i++;
return ((unsigned char)str1[i] - (unsigned char)str2[i]);
}
/*
1- Check if the s1 and s2 exist
2- Create new string with the value of s1 and other with s2
3- Check if the bytes(n) for check passed by functions its 0
- If its, return 0
4- Iterate as long as both strings are equal,
or as long as there are bytes left to check.
*/