#include <stdio.h>
int memcmp(const void* s1, const void* s2, size_t n) {
// compare the first n bytes of str1 and str2
const unsigned char* str1 = (const unsigned char*)s1;
const unsigned char* str2 = (const unsigned char*)s2;
for (; 0 < n; str1++, str2++, n--)
if (*str1 != *str2)
return *str1 < *str2 ? -1 : +1;
return 0;
}
int main()
{
char str1[32] = "c programming";
char str2[32] = "c programming";
int result = memcmp(str1, str2, 5);
if (result > 0) {
printf("str1 > str2");
}
else if (result < 0) {
printf("str2 > str1");
}
else {
printf("str1 == str2");
}
return 0;
}
/*
run:
str1 == str2
*/