Thread: is it this problem with my compiler????

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    Mysore, Karnataka, India
    Posts
    12

    Arrow is it this problem with my compiler????

    in this program the compiler is compiling the both else if and else statements simultaneously in same for loop..... i wanna know wat is problem with the program

    /* program to convert infix to postfix expression*/
    #include<stdio.h>
    #include<conio.h>

    order(char a[],int );
    void main()
    {
    int top=0,i,j=0,ok=0;
    char a[100],d[100],s[100];
    clrscr();

    printf("Enter the infix expression:\t");
    gets(a);

    s[top]='#';

    for(i=0;a[i]!='\0';i++)
    {
    if(a[i]==')')
    {
    for(;s[top]!='('
    d[j++]=s[top--];
    top--;ok=1;
    }
    else if((order(a,i))>(order(s,top))) /* the compiler is enterin the below else */
    s[++top]=a[i]; /* after enterin elseif statement*/
    else
    {
    d[j++]=s[top];
    s[top]=a[i];
    }
    }
    if(ok==0) top--;
    while(s[top]!='#')
    d[j++]=s[top--];

    printf("\nthe postfix expression is:");
    puts(d);
    getch();
    }

    int order(char a[],int i)
    {
    switch(a[i])
    {
    case '*':
    case '/':return 4;
    case '(':return 5;
    case '+':
    case '-':return 3;
    /* case ')':return 2;*/
    case '#':return 1;
    default:return 6;
    }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please post your well indented code in [code][/code] bbcode tags.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++ compiler problem
    By GrasshopperEsq in forum C++ Programming
    Replies: 19
    Last Post: 05-08-2008, 02:35 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Compiler Problem
    By sitestem in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2004, 03:48 PM
  4. Problem with compiler
    By knight543 in forum C++ Programming
    Replies: 4
    Last Post: 02-09-2002, 09:16 PM
  5. Please help me with this compiler problem
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2002, 05:14 PM