#include<stdio.h>
size_t str_len(const char* s)
{
const char* temp = s;
while('\0'!=*temp) temp++;
return temp - s;
}
char* str_cpy(char* dest,const char* src)
{
char* temp = dest;
while(*temp++ = *src++);
return dest;
}
char* str_cat(char* dest,const char* src)
{
char* temp = dest;
while(*temp) temp++;
while(*temp++ = *src++);
return dest;
}
int str_cmp(const char* s1,const char* s2)
{
while(*s1 && *s1 == *s2) s1++,s2++;
if(*s1 > *s2) return 1;
else if(*s1 < *s2) return -1;
else return 0;
}
C语言实现字符串常用函数strlen、strcpy、strcmp、strcat
最新推荐文章于 2021-08-09 10:48:37 发布