char *strcpy(char *strDest ,const char * strSrc )
{
if(strDest == NULL || strSrc == NULL)
return 0;
char *address = strSrc;
while((*strDest++ = *strSrc++) != '\0')
NULL;
return addressl;
}
//字符串比较函数,相等返回0,s1大返回正整数,s2大返回负整数
int mystrcmp(const char *s1,const char *s2)
{
while(*s1!='/0'&&*s2!='/0'&&(*s1==*s2)) s1++,s2++;
return (*s1)-(*s2);
}
//字符串长度函数,长度不包括结尾的'/0'
int mystrlen(const char *s)
{
int res = 0;
while(*s++!='/0')
res++;
return res;
}
//字符串连接函数
char *mystrcat(char *source,const char *dest)
{
if(source ==NULL
|| dest == NULL)
return 0;
char *s = source;
while(*s!='/0')s++;
while(*dest!='/0')*s++ = *dest++;
*s='/0';
return source;
}
//字符串转换小写字母函数
char *mystrlwr(char *source)
{
char *s = source;
do
{
if(*s>='A'&&*s<='Z')
*s+=32;
} while (*s++!='/0');
return source;
}
//字符串转换大写字母函数
char *mystrupr(char *source)
{
char *s = source;
do
{
if(*s>='a'&&*s<='z')
*s-=32;
} while (*s++!='/0');
return source;
}
/字符串倒转函数
char *mystrrev(char *source)
{
char *s1 = source,*s2 = source,temp;
while(*s2!='/0')s2++;
if(s1!=s2)s2--;//找中值,交换分界点
while(s1<s2)temp = *s1,*s1 = *s2,*s2 = temp,s1++,s2--;
return source;
}
//字符串查找指定字符串的第一次出现,没有出现返回NULL,出现则返回出现的位置
static const char* _strstr(const
char* s1, const char* s2)
{
assert(s2 && s1);
const char* p=s1, *r=s2;
while(*p!="\0”)
{
while(*p++==*r++);
if(*r=="\0”)
return p;
else
{
r=s2;
p=++s1;
}
}
return NULL;
}
- //strSrc指向的字符串循环右移n个字符后保存到strDest中并返回
-
char * circulate_right_move(char *strDest,const char *strSrc,const int n)
-
{
-
assert( (strDest != NULL) && (strSrc != NULL));
-
-
char * address = strDest;
-
int len = strlen(strSrc);
-
int offset = n % len;
-
-
strSrc += (len - offset);
-
-
for(;(*strDest = *strSrc) != '\0';strDest++,strSrc++);
-
-
strSrc -= len;
-
-
for(int i = 0; i < len - offset; i++)
-
{
-
*strDest = *strSrc;
-
strDest++;
-
strSrc++;
-
}
-
-
*strDest = '\0';
-
-
return address;
- }
感觉可以用CMP算法优化。