So I have to recreate the memcmp() function using C and my function works as expected. It returns the difference of the first character that does not match in both strings.
My function:
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *ptr1;
unsigned char *ptr2;
ptr1 = (unsigned char *)s1;
ptr2 = (unsigned char *)s2;
while (n && (*ptr1 == *ptr2))
{
ptr1++;
ptr2++;
n--;
}
if (n == 0)
return (0);
else
return (*ptr1 - *ptr2);
}
My main:
int main(void)
{
const char *s1 = "acc";
const char *s2 = "abc";
int res;
res = memcmp(s1, s2, 3);
printf("%i\n", res);
return (0);
}
So this main will return 256, but if you use my function (ft_memcmp) you get 1. Obviously the difference is 1 and not 256, but why does the original function return 256? With a difference of 2, I get 512...