This code is a linked list implementation of a stack that solves postfix problems in postfix.txt.
I stared the line that i am trying to convert.
I just want to make it a double before i put it on my stack so i cant do addition, subtraction, multiplication and division with it later. The error I get is saying “expected an expression”.
Thanks!
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();
}
You don’t want to “Convert” the byte array, you want to parse the string representation of the number into the correct data type.
First, you need to know if you’re going to be dealing with integers or floating point values. Then you’ll want to use scanf() or atoi()/atof() to read the values into an int or double. Those functions all take a char* argument though, so you’ll just pass
a, nota[].