c语言实现strcp函数

#include <stdio.h>
#include <string.h>
void main() {
    char *strcopy(char *target, char *source);
    char a[] = "hello world~";
    strcopy(a,"thanks!");
    printf("%s\n",a);
    getchar();

}
char *strcopy(char *target,char *source) {
    char *p = target;
    if (strlen(target) < strlen(source)) {
        return NULL;
    }
    while (*target++ = *source++) {
        if (*source == '\0') {
            break;
        }
    }
    *target = '\0';
    return p;
}

 

posted @ 2018-04-02 14:51  一梦、  阅读(926)  评论(0编辑  收藏  举报