terminating null character, stopping after the null charac-
ter has been copied. The strncpy() function copies exactly n
bytes, truncating s2 or adding null characters to s1 if
necessary. The result will not be null-terminated if the
length of s2 is n or more. Each function returns s1. If
copying takes place between objects that overlap, the
behavior of strcpy(), strncpy(), and strlcpy() is undefined.
在x86&Solaris系统上,strcpy函数出现复制出错,查看帮助后发现字符串类函数族要求不能出现源和目的重叠的情况,否则结果是不确定的,如下
int main(int argc, char *argv[])
{
char sid[64]={0};
int len;
char *sid = argv[1];
strcpy(sid, "141208301208558618237085283");
printf("sid,%s,%d\n", sid, strlen(sid));
if(strncmp(&sid[12], "86", 2)){
//strcpy( sid, &sid[2] ); 可能会出现错误
memmove(sid, &sid[2], strlen(sid)+1-2);
printf("sid2:[%s],%u\n", sid, strlen(sid));
}
return 0;
}