请仔细读strncpy的说明,长度是不会影响 strncpy 执行的, 个人认为错误三处就是: p 为空指针不能使用strncpy填充; i 会在循环时溢出; 函数返回函数内变量地址,此地址值不会出错,但是调用此此地的指向将会出错.
附strncpy的MSDN英文说明 The strncpy function copies the initial count characters of strSource to strDest and returns strDest. If count is less than or equal to the length of strSource, a null character is not appended automatically to the copied string. If count is greater than the length of strSource, the destination string is padded with null characters up to length count. The behavior of strncpy is undefined if the source and destination strings overlap.