-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_memcmp.c
38 lines (34 loc) · 866 Bytes
/
my_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
#include "libft.h"
int my_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned int count;
unsigned int cmp;
unsigned char *str1;
unsigned char *str2;
count = 0;
cmp = 0;
str1 = (unsigned char *)s1;
str2 = (unsigned char *)s2;
if (n == 0)
return (0);
while (count <= (n - 1))
{
cmp = str1[count] - str2[count];
if (str1[count] != str2[count])
return (cmp);
count++;
}
return (cmp);
}
/*
int main()
{
#include <stdio.h>
int arr1[] = {25, 50, 999999999, 100};
int arr2[] = {25, 50, 75, 100};
unsigned int number = 9;
printf("Retorno da minha my_memcmp(): %i\n", my_memcmp(arr1, arr2, number));
printf("Retorno da memcmp() original: %i\n", memcmp(arr1, arr2, number));
printf("\n\n Retorno da minha my_memcmp(): %i\n", my_memcmp("t\200", "t\0", 2));
printf("Retorno da memcmp() original: %i\n", memcmp("t\200", "t\0", 2));
}*/