如果您拥有字符串缓冲区,并且知道可以安全地修改,您可以strtok_r()按照人们的建议使用.或者你可以自己做,像这样:
char buffer[2048];
char *sp;
/* read packet into buffer here, omitted */
/* now find that space. */
sp = strchr(buffer, ' ');
if(sp != NULL)
{
/* 0-terminate the first part, by replacing the space with a '\0'. */
*sp++ = '\0';
/* at this point we have the first part in 'buffer', the second at 'sp'.
}
Run Code Online (Sandbox Code Playgroud)
根据上下文,这可能更快和/或更容易理解.