Runtime error in my code...

INFIX TO POSTFIX CONVERSION :

//Convert an infix expression to postfix expression...

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
char ifx[50],pfx[50],stk[50];
int top=-1,n;
void push(char ch)
{
    if(top!=n-1)
    {
        top++;
        stk[top]=ch;
    }
    else
        cout<<"\nThe stack is full.";    
}
char pop()
{
    char rmv;
    if(top!=-1)
    {
        rmv=stk[top];
        top--;
        return rmv;
    }
    else
        return '#';
}
char topele()
{
    char ch;
    if(top==-1)
    {
        ch='#';
        return ch;
    }   
    else
        ch=stk[top];
}
int chkpres(char ch)
{
    ch=topele();
    switch(ch)
    {
        case '^':return 7;
            break;
        case '/':return 6;
            break;
        case '*':return 5;
            break;
        case '+':return 4;
            break;
        case '-':return 3;
            break;
        default:return 0;
            break; 
     } 
}                 
/*int braces(char *s)
{
    int lftbr,rgtbr=0;
    for(int i=0;s;++i)
    {
        if(s=='(')
            lftbr++;
        else
            rgtbr++;
    }
    if(lftbr==rgtbr)
        return 0;
    else if(lftbr<rgtbr)
        return 1;
    else return -1;
}*/
int main()
{
    char ele,elem,chk,popp,topp;
    int pre,pres;
    cout<<"\nEnter how many elements you want to enter in the infix expression: ";
    cin>>n;
    cout<<"\nEnter the infix expression: ";
    for(int i=0;i<n;++i)
        cin>>ifx; 
    topp=topele();
    strcpy(pfx," ");
    for(int i=0,j=0;ifx!='\0',pfx[j]!='\0';++i,++j)
    {
        ele=ifx;
        if(ele!='^' && ele!='*' && ele!='/' && ele!='+' && ele!='-')
            pfx[j++]=ifx;
        else if(ele=='^'||ele=='*'||ele=='/'||ele=='+'||ele=='-')
        {
            if(topp=='^'||topp=='*'||topp=='/'||topp=='+'||topp=='-')
            {
                pre=chkpres(ele);
                pres=chkpres(topp);
                if(pre>pres)
                {
                    push(pre);
                    top++;
                }
                else if(pre<=pres)
                    pfx[j++]=pres;
            }    
            else
            {
                push(ele);
                topp=ele;
            }
        }
        else if(ele=='(')
        {
            i++;
        }
        else if(ele==')')
        {
            while(topp!='#')
            {
                popp=topp;
                pfx=popp;
            }
        }
        cout<<"---------------"<<pfx[j++];
    }
    cout<<"\nThe postfix expression is: ";
    for(int i=0;pfx!='\0';++i)
    {
        cout<<pfx;
    }
    cout<<endl;
return 0;
}

Is that the error, or do we need to dig out our Bjarne Stroustrup books?

Have you tried adding some debug?

Yes, I have debugged this whole code. But what do you mean why adding some debug?
Actually the runtime error here is that my postfix expression is showing only a single character.

For example:

Would you please help me work it out?

This loop:

for(int i=0,j=0;ifx!='\0',pfx[j]!='\0';++i,++j)

I don't think it does what you think it does.

Particularly this expression: ifx!='\0',pfx[j]!='\0' Listing more than one in a row with commas doesn't do a logical and. It evaulates both statements, but only gives you the result of the second one! I think you must have meant (ifx!='\0')&&(pfx[j]!='\0')

But that corrected expression still doesn't do what you think it does, because you're still assuming char arrays are strings. They're not exactly equivalent -- all strings may be char arrays, but that doesn't make all char arrays strings! NULLs don't just appear, something has to put them there.

// C adds a NULL at the end of "" strings for you
char *str="abcd";

// The C str* functions write NULLs, but also *need* nulls to work in the
// first place!  "asdf" has a NULL, so it works, and puts asdf\0 in buf[].
char buf[256]; strcpy(buf, "asdf");

// BUT an array is still JUST AN ARRAY.  It does not magically set other
// elements for you.  Setting b[0]='a', b[1]='b' does NOT set b[2]='\0'.
// It MIGHT have started that way, if you're lucky.  Or it might be garbage,
// or still hold a value you put in it last time, leaving your own code
// blissfully unaware that you intended the string to STOP at position 2.
char b[256]; b[0]='a'; b[1]='b';

// THIS is what a string is.
char c[256]; c[0]='a'; c[1]='b', c[2]='\0';

With that in mind, let's look at your loop again:

for(int i=0,j=0;(ifx!='\0')&&(pfx[j]!='\0');++i,++j)

At program start, the contents of your pfx[] array are {' ', '\0', ???????? } because you called strcopy on it. The ???????? elements could be anything since nothing's been assigned to them yet.

First loop, i=0,j=0. It finds 'a' in ifx, so sets pfx[0]=ifx[0] (which happens to be 'a'), then adds 1 to j (because of pfx[j++]=...), then goes back up the for-loop, which adds to j again because of ++j.

Second loop, i=1, j=2. It checks if pfx[2], aka ?, is NULL. By sheer coincidence, it is, so the for-loop's condition becomes false, breaking the loop.

Some thoughts.
1) Why are you checking the value of pfx in the for-loop? You're writing to pfx, you don't need to care what used to be in it.

2) Why are you adding ++j every single loop? Not every loop will add a char. You could end up setting pfx[0], then pfx[3], then pfx[5], which will either create a string full of garbage or a string that ends too soon (depending on the previous contents of pfx). Only increment j when you actually add anything to pfx. You're also adding extra to i in places.

3) Why are you checking for NULLs when you have no strings? Either just use the length you got from before, or make it a string. When you want a string, the cheap+easy way is to use string functions:

#include <stdio.h> // for fgets
#include <ctype.h> // for isspace
#include <string.h> // for strchr, etc.

...

int i,j;
char pfx[50];
char ifx[50];

// Set everything in PFX to NULL.  As long as we set pfx[n] in order 0,1,2,...
// and don't go past pfx[48] it will always be a string now.
memset(pfx, 0, sizeof(pfx));
 
// Reads an entire raw line into buf, and adds the NULL terminator.
// You don't need to be told how long your expression is any more.
fgets(ifx, 50, stdin);

for(i=0,j=0; ifx != '\0'; ++i)
{
        cout << "Beginning of loop, i="<<i<<" j=" <<j<<"\n";

        if(isspace(ifx))
        {
                cout << "Ignoring space/line\n";
                continue;  // Ignore spaces and newlines
        }


        // Check ONCE and save the result so we don't need the same huge
        // if-statement three times.
        pre=chkpres(buf);

        if(ifx == '(') // Check this first to make it simpler
        {
                cout << "got (\n";
                // I don't understand why you had i++ here.  i already gets
                // incremented every loop by for().  I suspect you're supposed to
                // do something to the stack instead.
        }
        else if(ifx == ')')
        {
                cout "got )\n";
                ...
        }
        else if(pre == 0) // Not a mathematical operator
        {
                cout << "got variable: "<<ifx<<"\n";
                pfx[j++]=ifx;
        }
        else // Guaranteed to be a mathematical operator
        {
                cout << "got operator: "<<ifx << " ";

                if(chkpres(topp) != 0)
                {
                     cout << "and top is also operator: "<<topp<<"\n";
                     // If topp is an operator
                }
                else
                {
                    cout << "but topp isn't an operator: "<<topp<<"\n";
                     // topp isn't an operator
                }
        }
}
// since pfx is guaranteed to be a string, we can print it in one whack
cout << "Loop done.  pfx is: " << pfx << "\n";