title: Problem in converting infix expression to a prefix one
body: <p>Here I am converting an infix expression to a prefix expression.</p>
  
  <p>For some test cases my result is perfect. </p>
  
  <p>But for certain test cases I get an output which is correct according to some sites but wrong according to other sites. So I am in a dilemma as to whether my code is correct or not.</p>
  
  <p>For example, if infix expression is: </p>
  
  <pre><code>A+B*C+D
  </code></pre>
  
  <p>then output according to my code is:</p>
  
  <pre><code>+A+*BCD
  </code></pre>
  
  <p>But some site mentions the output as: </p>
  
  <pre><code>++A*BCD 
  </code></pre>
  
  <p>for the same input.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  int main()
  {
      int top=-1,k=0,i,l,top2=-1,j,a,t,m,t1;
      char s[100] ,s2[100],n, main[100];
      char q[100],p[100];
      printf("\nenter string :");
      gets(main);
      for(i=strlen(main)-1;i&gt;=0;i--)
      {
          if(main[i]=='(')
          {
            q[k]=')';
          }
          else if(main[i]==')')
          {
              q[k]='(';
          }
          else
          {
              q[k]=main[i];
          }
  
          q[k+1]='\0';
          k++;
      }
      k=0;
      strcat(q,")");
      s[++top]='(';
      for(i=0;i&lt;strlen(q);i++)
      {
  
          if(q[i]&gt;='a' &amp;&amp; q[i]&lt;='z'   || q[i]&gt;='A' &amp;&amp; q[i]&lt;='Z' || q[i]&gt;='0' &amp;&amp; q[i]&lt;='9')
          {
              p[k]=q[i];
              p[k+1]='\0';
              k++;
          }
  
          else if (q[i]=='(')
          {
              s[++top]=q[i];
          }
  
          else if (q[i]==')')
          {
              for(j=top;j&gt;=0;j--)
              {
                  if(s[j]!='(')
                  {
                      s[top--];
                      p[k]=s2[top2];
                      p[k+1]='\0';
                      s2[top2--];
                      k++;
  
                  }
                  else
                      break;
              }
              s[top--];
  
          }
          else if(q[i]=='+' || q[i]=='-' || q[i]=='*' || q[i]=='/' || q[i]=='^' || q[i]=='%')
          {
  
                if(q[i]=='+' || q[i]=='-')
              {
                 n='1';
              }
              else if(q[i]=='*' || q[i]=='/' || q[i]=='%')
              {
                  n='2';
              }
              else if (q[i]=='^')
              {
                 n='3';
              }
  
                  t=n-48;
  
               if(top2!=-1)
               {
             for(j=top;j&gt;=0;j--)
             {
                t1=s[j]-48;
  
                 if(t&lt;=t1 )
                 {
                      s[top--];
                      p[k]=s2[top2];
                      p[k+1]='\0';
                      k++;
                      s2[top2--];
  
                 }
                 else if(s[j]=='(')
                          break;
  
              }
              }
               s[++top]=n;
               s2[++top2]=q[i];
          }
  }
  k=0;
  for(i=strlen(p)-1;i&gt;=0;i--)
  {
      main[k]=p[i];
      main[k+1]='\0';
      k++;
  }
  printf("\nFINAL ANSWER :\n");
  printf("\n%s",main);
  }
  
  </code></pre>