So this is a homework I have for my university. I have to read a polish notation from a line in a text file. The expression in the text file is: "/ 2 3 " and i have to turn it into a reversed polish notation. I keep getting this error: 0xC0000005: Access violation reading location 0x00000000.
int top = -1;
char prefix[50];
void Push(char value)
{
top++;
prefix[top] = value;
}
void Pop()
{
if (top < 0)
cout << "The stack is empty." << endl;
else
{
top--;
}
}
char Top()
{
return prefix[top];
}
void Display()
{
for (int i = 0; i <= top; i++)
cout << prefix[i] << " ";
}
bool isOperator(char c)
{
if (c == '+' || c == '-' || c == '*' || c == '/')
return true;
else
return false;
}
char c;
char postfix[50];
int top2 = -1;
void Push2()
{
top2++;
postfix[top2] = Top() + Top() + c;
}
void Display2()
{
{
for (int i = 0; i <= top2; i++)
cout << postfix[i] << " ";
}
};
void PrefixToPostfix()
{
for (int *i = 0; *i <= top2; i++)
{
c = prefix[*i];
if (isOperator)
{
Push2();
}
else
{
top2++;
postfix[top2] = c;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char value;
char c;
ifstream file("Prefix.txt");
while (file >> value)
{
Push(value);
}
file.close();
PrefixToPostfix();
Display();
Display2();
cout << endl;
system("PAUSE");
return 0;
}
i think the error might be in this part of my code:
void PrefixToPostfix()
{
for (int *i = 0; *i <= top2; i++)
{
c = prefix[*i];
If someone can help me, I would be very thankful because i have to turn in my homework in 5 hours. :)