void*my_memset(void*str, int set, size_t count)
{
assert(str);
void*p = str;
while (count--)
{
*(int*)str = set;
str = (int*)str + 1;
}
return p;
}
memcmp也是一樣的道理,代碼如下:
int my_memcmp(void*buf1, void*buf2, size_t count)
{
assert(buf1);
assert(buf2);
while (count--)
{
if (*(char*)buf1 == *(char*)buf2)
{
buf1 = (char*)buf1 + 1;
buf2 = (char*)buf2 + 1;
}
else
{
if (*(char*)buf1 > *(char*)buf2)
{
return 1;
}
else
{
return -1;
}
}
}
return 0;
}