c语言:str.c copypath

#include <stdio.h>
#include <string.h>
static void
copypath(const char *src, char *dst, size_t dstlen)
{
        char *end = dst + dstlen - 1;

        /* Copy the string, substituting the directory separator */
        for (; dst < end && *src != '\0'; src++, dst++)
                *dst = *src;
        *dst = '\0';
}

int main()
{
    char path1[60];
    strcpy(path1,"/home/lyd/myword/pid/abc");
    char path2[60];
    copypath(path1,path2,10);
    printf("%s",path2);
}

 

posted on 2021-01-19 18:23  lydstory  阅读(84)  评论(0)    收藏  举报

导航