此代碼是解決postfix.txt中的postfix問題的堆棧鏈表實現。如何將char數組轉換爲整數或雙精度?
我盯着我想轉換的線。 我只是想讓它成爲一個雙倍,然後我把它放在我的堆棧上,所以我不能在後面進行加法,減法,乘法和除法。我得到的錯誤是說「預期的表達」。 謝謝!
void main()
{
ifstream postin("postfix.txt");
char oper;
char a[100];
int i=0;
while(oper != '$')
{
stack operands;
while(oper != '/n'&& oper != '$')
{
while(oper != ' '&&oper != '/n'&& oper != '$')
{
oper = postin.get();
if(oper != '+' || oper != '*' || oper != '-' || oper != '/')
{
do
{
a[i]= oper;
i++;
}while(oper != ' ');
************************************************double number = atoi(a[]);
operands.Push(number)
}
else
{
double b = operands.Pop();
double a = operands.Pop();
if(oper == '+')
{
operands.Push(a+b);
}
else if(oper == '-')
{
operands.Push(a-b);
}
else if(oper == '/')
{
operands.Push(a/b);
}
else
{
operands.Push(a*b);
}
}
}
}
}
postin.close();
}
確定'/ N'做你想要的嗎? – 2012-03-26 05:18:36