编辑:新问题
char * symbolInList = listOfSymbolTokens[0];
char * addressOfSymbol = listOfSymbolTokens[1];
printf("symbolLookingFor: %s\n", symbolLookingFor);
printf("symbolInList: %s\n", symbolInList);
printf("addressOfSymbol: %s\n", addressOfSymbol);
if (strcmp(symbolInList, symbolLookingFor) == 0) {
strcpy(tokenAddress, addressOfSymbol);
return;
}
printf("did not enter for loop\n");
出于某种原因,strcmp(symbolinList, symbolLookingFor) 即使它们相同也不会返回 0。
symbolLookingFor: abc
symbolInList: abc
addressOfSymbol: 3011
did not enter for loop
不进入if语句
最佳答案
这是错误的
const char sdilem[1] = " ";
要存储 ""
字符串,缓冲区中至少需要 2 个字符。 (在 C 中这不是错误。)
首先,为了避免此类错误,您不需要显式指定大小
const char sdilem[] = " ";
其次,在这种情况下你可以使用
const char *sdilem = " ";
关于c - strtok() 非常奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40010351/