我正在研究一个Postfix计算器。我尝试了fscanf
和fgets
两个单独的双位数字。当我扫描文件时,两个数字分别在代码中继续。 25
将是2
和5
。
char Operand[20];
fgets(Operand, 20, Filepath);
for(i = 0; i < strlen(Operand); i++){
if(Operand[i] == ' ' ){
continue;
}
if( isdigit(Operand[i])){
PushOperand = (char *)malloc(sizeof(char));
*PushOperand = Operand[i];
Push(stack, PushOperand );
}
else{
num1 = Pop(stack);
num2 = Pop(stack);
number1 = atoi(num1);
number2 = atoi(num2);
operator = Operand[i];
value = GetValue(operator, number1, number2);
pushVal = &value;
Push(stack, pushVal);
}
}