Sponsored Content
Full Discussion: Runtime error in my code...
Top Forums Programming Runtime error in my code... Post 302513998 by poonam.gaigole on Thursday 14th of April 2011 01:15:36 PM
Old 04-14-2011
Runtime error in my code...

INFIX TO POSTFIX CONVERSION :

Code:
//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];++i)
    {
        if(s[i]=='(')
            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[i]; 
    topp=topele();
    strcpy(pfx," ");
    for(int i=0,j=0;ifx[i]!='\0',pfx[j]!='\0';++i,++j)
    {
        ele=ifx[i];
        if(ele!='^' && ele!='*' && ele!='/' && ele!='+' && ele!='-')
            pfx[j++]=ifx[i];
        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[i]=popp;
            }
        }
        cout<<"---------------"<<pfx[j++];
    }
    cout<<"\nThe postfix expression is: ";
    for(int i=0;pfx[i]!='\0';++i)
    {
        cout<<pfx[i];
    }
    cout<<endl;
return 0;
}

 

9 More Discussions You Might Find Interesting

1. Solaris

Runtime error...

My interprise use a UNIX mainform for a instrumentation process control. The control use the FOXBORO INVENSYS system and they donīt gonna solve the problem the run time error. The run time error happen without logic explication. When everything itīs run perfectely and happenly appears the run time... (1 Reply)
Discussion started by: marpin
1 Replies

2. UNIX for Dummies Questions & Answers

Runtime Error...

My system did stay appears the error Run Time Library Error. What itīs? When the error appear, iīve to reboot my system and lost all I did. Is there the UNIX System problem? Please. I need help!!! (4 Replies)
Discussion started by: marpin
4 Replies

3. Solaris

Re:How to get the path during runtime?

Thank u vgesh99 It works well.. (1 Reply)
Discussion started by: Nandagopal
1 Replies

4. Programming

Runtime error in C++ Program - Help

All, I am getting this when i try to ran a program in HP unix. Things i came across 1. i have a system HP-UNIX where this same exe is working. 2. We have set a new HP_UNIX with the same configration and copied the exe to the new system we are getting this error. 3. Only... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

5. Shell Programming and Scripting

error code 137 and error code 35072

Hi while trying to run few scripts /afs/ae.ge.com/informatica/ardw/dev/bin/cdw_ar_update_recvbal.sh this script contains the below data load_dir=/afs/ae.ge.com/informatica/ardw/dev/data prog_dir=/afs/ae.ge.com/informatica/ardw/dev/bin ctl_dir=/afs/ae.ge.com/informatica/ardw/dev/ctl... (1 Reply)
Discussion started by: laxmi131
1 Replies

6. Programming

Help... runtime error in my maxheap sort program

#include<iostream> using namespace std; int *a,size,heapsize; void maxheap(int *a,int j) { int l,r,largest,temp; l=2*j; r=(2*j)+1; for(j=0;j<size;++j) { if(l<=heapsize && a>a) largest=l; else largest=j; if(r<=heapsize... (5 Replies)
Discussion started by: poonam.gaigole
5 Replies

7. UNIX for Dummies Questions & Answers

No Java runtime environment (JRE) error

Hi all, I am trying to install a .bin file for that it requires IBMJava2-AMD64-142-JRE-1.4.2-13.8.x86_64.rpm to be installed. I have installed this rpm but when i try to install .bin file, it complains that no JRE found. How to solve this. Thanks in advance! #... (0 Replies)
Discussion started by: lramsb4u
0 Replies

8. Programming

Fortran runtime error: Insufficient data descriptors in format after reversion

Hello, I have some Fortran code that is providing the following error: At line 1165 of lapc_shells_2.f Fortran runtime error: Insufficient data descriptors in format after reversion Here are the lines just above and including 1165: WRITE (*,"('ATTEMPTING TO READ PLATE... (1 Reply)
Discussion started by: jm4smtddd
1 Replies

9. Red Hat

Runtime Error Enable user directory apache

Hi I am exactly according to this link CentOS 6 - Apache httpd - Enable Userdir : Server World I Enabled userDirectory Server version: Apache/2.2.15 CentOS release 6.8 (Final) But Iget this Error Forbidden You don't have permission to access /~mn/index.html on this server Goal... (2 Replies)
Discussion started by: mnnn
2 Replies
POSTFIX-ADD-FILTER(8)					      System Manager's Manual					     POSTFIX-ADD-FILTER(8)

NAME
postfix-add-filter - add filter service to Postfix master.cf SYNOPSIS
postfix-add-filter [smtp service name...] [smtpd port...] DESCRIPTION
The postfix-add-filter(8) command adds an smtp service named smtp service name and and smtpd server listening on smtpd port to etc/post- fix/master.cf to facilitate integration of SMTP filters such as amavisd-new or clamsmtp. The configuration is based on the upstream recom- mendations for amavisd-new 2.6.0. Adminstrators should verify it is appropriate for their requirements. The original file is copied prior to modification and left in /etc/postfix to make it possible to revert changes easily. Available in the Debian package for Postfix version 2.5.3 and later. DIAGNOSTICS
If the given smtp service name or smtpd port already appear in the master.cf, a message will be printed to standard out and master.cf will not be modified. ENVIRONMENT
MAIL_CONFIG Directory with Postfix configuration files. The postfix-add-filter(8) command should use this, but it currently doesn't. It is hard coded to /etc/postfix. This should be changed. CONFIGURATION PARAMETERS
None FILES
/etc/postfix/master.cf SEE ALSO
postconf(5), Postfix configuration LICENSE
This software is licensed under the MIT open source license. AUTHOR(S) Scott Kitterman <scott@kitterman.com> POSTFIX-ADD-FILTER(8)
All times are GMT -4. The time now is 11:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy