my_strlen
int my_strlen(char * str)
{
int len = 0;
char * temp = str;
while((*temp) != '\0')
{
temp++;
len++;
}
return len;
}
my_strcmp
int my_strcmp(char * str1,char * str2)
{
char * s1 = str1;
char * s2 = str2;
while(*s1 != '\0')
{
if(((*s1) > (*s2)) || (*s2 == '\0'))
{
return 1;
}
if((*s1) < (*s2))
{
return -1;
}
}
if(*s2 != '\0')
{
return -1;
}
else
{
return 0;
}
}
my_strcat
void my_strcat(char * str,char * dest)
{
char * s = str;
char * d = dest;
while((*s) != '\0')
{
s++;
}
while((*d) != '\0')
{
*s = *d;
s++;
d++;
}
}
以上代码并未做入口参数检查及地址有效性检查,改进版本将在之后发布。