strtok()的疑问
// Read the command line.
char szTokens[] = "-/" ;
char* szToken = strtok(lpCmdLine, szTokens) ;
while (szToken != NULL)
{
if (_stricmp(szToken, "UnregServer") == 0)
{
CFactory::UnregisterAll() ;
// We are done, so exit.
bExit = TRUE ;
bUI = FALSE ;
}
else if (_stricmp(szToken, "RegServer") == 0)
{
CFactory::RegisterAll() ;
// We are done, so exit.
bExit = TRUE ;
bUI = FALSE ;
}
else if (_stricmp(szToken, "Embedding") == 0)
{
// Don't display a window if we are embedded.
bUI = FALSE ;
break ;
}
szToken = strtok(NULL, szTokens) ;
}
请问红色标注的部分的作用是什么?
[解决办法]
作用是对余下的字符串再次进行strtok();不包括已经已经分开的字符串。
比如,hell:world:ll
你对该字符串进行strtok();分割条件是":",你第一次使用strtok();后,如果下次你还以":"作为分割条件,那么strtok():的第一个参数是:NULL。它是对字符串:world:ll进行分割。