我有一个字符串:
char * someString;
如果我想要该字符串的前五个字母并将其设置为
otherString
,我该怎么做? 最佳答案
#include <string.h>
...
char otherString[6]; // note 6, not 5, there's one there for the null terminator
...
strncpy(otherString, someString, 5);
otherString[5] = '\0'; // place the null terminator