is it this problem with my compiler????

This is a discussion on is it this problem with my compiler???? within the C Programming forums, part of the General Programming Boards category; in this program the compiler is compiling the both else if and else statements simultaneously in same for loop..... i ...

  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
    21,440
    Please post your well indented code in [code][/code] bbcode tags.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 08:16 PM
  5. Please help me with this compiler problem
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2002, 04:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21