题目:
用c语言实现拷贝字符串strcpy()函数。将字符串一逆向拷贝到字符串二中。
思路:
将字符串一从右到左逐一拷贝到字符串二中。
代码:
char *StringReverseCopy(char *strDest, char *strSrc)
{
if(strDest == NULL || strSrc == NULL)
{
return NULL;
}
int len = StringLength(strSrc);
int i = len-1;
int j = 0;
while(len-- >= 0)
{
strDest[j] = strSrc[i];
j++;
i--;
}
return strDest;
}
注:代码中所用到的求字符串长度的StringLength()函数请看“求字符串长度”