不能使用库函数 不能定义其他的变量 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);
    }
}

posted on 2011-11-25 02:19 メmarsメ 阅读(186) 评论(0)  编辑 收藏 引用 所属分类: AL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜