#include "stdafx.h"
#include <stdio.h>
#include <string.h>
void * Memset(void *dest , char c ,size_t count)
{
char *p = (char*)dest;
size_t i = 0;
while(i < count)
{
*p = c;
++p;
++i;
}
return dest;
}
void * Memcpy(void *dest , void *src , size_t count)
{
char *pd = (char*)dest;
char *ps = (char*)src;
size_t i = 0;
while(i<count)
{
*pd = *ps;
++pd,++ps;
++i;
}
return dest;
}
int MemCmp(void *s1 , void *s2 , size_t count)
{
char *p1 = (char *)s1;char *p2 = (char *)s2;
while(*p1 == *p2 && --count)
{
++p1;++p2;
}
if(*p1 > *p2)
return 1;
else if (*p1 < *p2)
return -1;
else
return 0;
}
int main(int argc, char* argv[])
{
int i = -1;
int j = 1;
//memset(&i,0,sizeof(int));
Memcpy(&i,&j,sizeof(int));
int a[3] = {-1,1,255};
int b[3] ;
Memset(b,0,sizeof(b));
Memcpy(b,a,sizeof(b));
char s1[] = "abcd123";
char s2[] = "bccd234";
int nRes = MemCmp(s1,s2,1);
if (nRes > 0)
puts("前面大");
else if(nRes < 0)
puts("后面大");
else
puts("一样大");
return 0;
}
简单mem族函数的实现
最新推荐文章于 2022-04-01 21:02:15 发布