不能使用库函数 不能定义其他的变量 strcpy逆序拷贝

不能使用库函数 不能定义其他的变量 strcpy逆序拷贝

写C语言的拷贝函数,要求复制字符串,并且将复制后的字符串逆序 比如from中是1234, 则to中是4321 void strcyp(char * to,const char * from)问题补充:   
要求: 不能使用库函数 不能定义其他的变量。

#include <stdio.h>
#include <assert.h>

void recopy2( char ** pto,  char * from)
{
     if ('\0' != *from)
    {
        recopy2(pto, from + 1);
        *((*pto)++) = *from;
    }
}

void recopy1( char * to,  const  char * from)
{
    assert(NULL != to && NULL != from);
    recopy2(&to, ( char *)(from));
    *to = '\0';
}

void main()
{
    {
         char src[5] = "1234";
         char des[6] = "abcde";

        printf("before: %s -- %s\r\n", src, des);

        recopy1(des, src);

        printf("after:  %s -- %s\r\n", src, des);
    }

    {
         char src[5] = "1234";
         char des[5] = "abcd";

        printf("before: %s -- %s\r\n", src, des);

        recopy1(des, src);

        printf("after:  %s -- %s\r\n", src, des);
    }
}

你可能感兴趣的:(不能使用库函数 不能定义其他的变量 strcpy逆序拷贝)