我在C中實現了pass 2 assembler並試圖使用strtok()
來獲取表達式的條件。該函數正確運行在while
循環內,但它不會正確生成令牌。strtok()函數不正確地標記字符串
下面是用於生成令牌的代碼:
char *terms[50];
char *operand="THREE-3"
char delimit[] = "+-\*";
int k = 0;
terms[k] = strtok(operand,delimit);
while(terms[k] != NULL)
{
printf("token [%d]=%s\n",k,terms[k]);
k++;
terms[k]=strtok(NULL,delimit);
}
這是輸出中:
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=3
token [0]=THREE
token [1]=3
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE
token [0]=THREE