当我的代码中没有调用相同的函数时,一切都运行良好。但是当函数从递归返回时,变量pch
突然为NULL:
void someFunction()
{
char * pch;
char tempDependencies[100*64+100];
strcpy(tempDependencies,map[j].filesNeeded);
pch = strtok(tempDependencies,",");
while (pch != NULL)
{
someFunction(); <- if i comment this out it works fine
pch = strtok (NULL, ",");
}
}
因此,例如,当循环作用于字符串
file2,file3,file4
时,它会正确地分割file2
并修改该字符串为file2\\000file3,file4
,但是下一个对pch = strtok(NULL, ",");
的调用会导致pch
成为0x0
。在递归调用时,我没有意识到的问题吗?