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);
}
浙公网安备 33010602011771号