/*************************************************************************
> File Name: test.cpp
************************************************************************/
#include"stdlib.h"
#include"stdio.h"
#include"string.h" char *mystrcat(char *dest,const char *src)
{
char* temp = dest;
while(*dest != '\0')
{
dest++;
} while((*dest++ = *src++) != '\0'); return temp;
}
char *mystrncat(char *dest,const char *src,size_t n)
{ char* temp = dest;
while(*dest != '\0')
{
dest++;
} while(n--> && (*dest++ = *src++) != '\0'); return temp;
} void* mymemset(void *s, int c, size_t n )
{
unsigned char uc = c;
unsigned char *su = (unsigned char*)s;
while(n-->)
{
*su = uc;
su++;
}
} int mystrlen(const char* str)
{
return *str?(mystrlen(++str)+):;
/*
const char* eos = str;
while(*eos++);
return (eos-str-1);
*/
} void* mymemcpy(void*dst, const void* src,size_t size)
{ if(src==NULL || dst==NULL) return NULL;
void* ret = dst;
while(size--)
{
*(char*)dst = *(char*)src;
dst = (char*)dst + ;
src = (char*)src + ;
}
return ret;
} void* mymemmove(void*dst, const void* src,size_t size)
{
if(src==NULL || dst==NULL) return NULL;
char* psrc;
char* pdst;
//存在覆盖,自后向前进行拷贝
if((src<dst) && (char*)src+size > (char*)dst)
{
psrc = (char*)src + size-;
pdst = (char*)dst + size-;
while(size--)
*pdst-- = *psrc--;
}
else
{
psrc = (char*)src;
pdst = (char*)dst;
while(size--)
{
*pdst++ = *psrc++;
}
}
} int mymemcmp(const void * ptr1, const void * ptr2, size_t num)
{
if(ptr1==NULL || ptr2==NULL || num<) return ; char* pch1 = (char*)ptr1;
char* pch2 = (char*)ptr2; while(num-- && *pch1++ == *pch2++);
return (pch1-pch2)<<;
} int mystrcmp ( const char * str1, const char * str2 )
{
if(str1==NULL || str2 ==NULL) return ; while(*str1 == *str2)
{
str1++;
str2++;
} return (*str1-*str2);
} int mystrncmp( const char * str1, const char * str2, size_t num )
{ if(str1==NULL || str2 ==NULL) return ; while(num-- && *str1 == *str2)
{
str1++;
str2++;
} return (*str1-*str2);
} int main()
{
char ch1[] = "hello";
char ch2[] = "herld";
// printf("strcat : %s\n", mystrncat(ch1,ch2,2)); printf("%d\n",mystrcmp(ch2,ch1)); printf("%d\n",mystrncmp(ch2,ch1,)); return ;
}