所以问题是我不确定为什么当我在文件的标准输入上使用strtok时,我无法触摸数据。我可以用'puts'打印出令牌,但我不能用printf打印出来,除非我在它前面和后面有换行符。这是我的代码。
我最初发现代码到达chooseOp函数时,我尝试使用strcasecmp,并且它会出现故障。
while( fgets ( line, sizeof line, stdin) != NULL){
//Get the instruction from stdin
token = strtok(line, "\t , \n"); // first token, should be a command
//puts(line);
//puts(token);
chooseOp(head, token);
regindex = 0;
token = strtok(NULL, " ,\n \t");
while( token != NULL){
puts(token);
if(token[0] != '='){ //If not the arrows than do whatever you want
createReg(head, token, regindex);
regindex++;
}
else{
regindex = 2; //If arrows, then point to next in line
}
token = strtok(NULL, " ,\n\t");
}
...
}
void chooseOp(Instruction head, char* token){
//Simple function to find the opcode responsible for this instruction
if(strcasecmp("nop", token) == 0){
head->opcode= NOP;
head->ismem=1;
head->latency = 1;
}
...
}