C++ - 实现strcpy函数

分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net 

/*
 * Created by Chimomo
 */

#include "stdio.h"

/**
 * Copies a string.
 *
 * @param dest The destination string.
 * @param src The null-terminated source string.
 * @return Returns the destination string.
 */
char *myStrCpy(char *dest, const char *src) {
    char *tmp = dest;

    while (*dest++ = *src++);
    *dest = '\0';

    return tmp;
}

int main(int argc, char *argv[]) {
    char s1[] = "Hello, World!";
    char s2[20];
    myStrCpy(s2, s1);
    printf("%s\n", s2);
    return 0;
}

// Output:
/*
Hello, World!

*/

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页