By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,806 Members | 1,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,806 IT Pros & Developers. It's quick & easy.

infix to postfix string translation error

P: 1
i am trying to convert a string from infix to postfix but not getting the desired output
my code is as follows:

#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
using namespace std;
int expr();
int term();
int match(int t);

int lookahead=0;

int expr()
{
term();
while(true)
{
if(lookahead = '+')
{
match('+');
term();
putchar('+');
}
else if(lookahead = '-')
{
match('-');
term();
putchar('-');
}
else
break;
}
}

int term()
{
if( isdigit (lookahead))
{

cout<<lookahead;
match(lookahead);
}
else
cout<<"syntax error";
}

int match(int t)
{
if(lookahead==t)
lookahead=getchar();
else
cout<<"syntax error";
}

int main()
{

cout<<"Enter an infix epression"<<endl;
lookahead=getchar();
cout<<"postfix expression is :";
expr();
getch();
return 0;
}
Mar 10 '17 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
There are two places where you use = instead of == in comparing lookahead to a character.
Mar 10 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.