infix to postfix
<blockquote>
  <p>The program is successfully compiled but when I try to convert the following infix expression 'A * B + C / D', I get this error message: Segmentation fault (core dumped). It works for some expression like this ' a+b-c*d/e' but i don't know is it correct or not. </p>
</blockquote>

<pre><code>#include&lt;iostream&gt;
#include&lt;stack&gt;
#include&lt;string&gt;
using namespace std;

string infix;  // infix exression string
string operand;
string operate;
stack &lt;string&gt; mystack; // this stack is used to push the operator
string postfix;  // postfix string where the operand is appended

//....................................................................
// this function read the infix expression from user 
string input()
{
 cout&lt;&lt;" Enter the damn infix expression: "&lt;&lt;endl; 
 getline(cin, infix);
 return infix;
}
//......................................................................
// this function checks for operator precedency in the stack
int precedence(string e)
{
int f;
if(e == "*" || e== "/" || e =="%")
 f = 2;
else
{
if(e == "+" || e == "-")
 f = 1;
}

if(e=="."){
f=0;
}

return f;

}




//....................................................................
// This function converts infix to postfix
string convert()
{ 
 for(int i=0; i&lt;infix.length(); i++)
 { 

 switch(infix[i]){

 // operate case start  
 case '+': case'-': case'*': case'/': case'^': case '(': case ')': case'.':

 operate=infix[i];
 {
  if(mystack.empty() || precedence(operate)&gt;= precedence(mystack.top()))
  {
   mystack.push(operate);    
   break;
  }       

  else 
  {
   while(precedence(operate)&lt; precedence(mystack.top()))
   {
    postfix.append(mystack.top());
    mystack.pop();
   }

   mystack.push(operate); 


  }
 }//operate case closed

 default:        //when operand string char is parsed
  {
                        operand=infix[i];
                        postfix.append(operand);
                        break;

  } // default case closed

 }//switch closed

 }// for loop close

 while(!mystack.empty())
 {
  postfix.append(mystack.top());
  mystack.pop();
 }

return postfix;
cout&lt;&lt;postfix;

} // function close braces



//...................................................................
int main()
{

input();

convert();
cout&lt;&lt;"postfix is "&lt;&lt;postfix&lt;&lt;endl;
} 
</code></pre>
