Thread: Converting Infix 2 Postfix

  1. #1
    Unregistered
    Guest

    Converting Infix 2 Postfix

    Can someone pls help me?
    I cant get my program to work
    Here's the code

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    extern void InitializeStack (stack *S);
    extern int FullStack (stack *S);
    extern int EmptyStack (stack *S);
    extern void Pop (stack *S,int *X);
    extern void Push (stack *S, int X);

    void main(){
    stack s;
    char str[100],PFstring[100],a;
    int i=0;
    PFstring[0]='\0';
    printf("Enter infix expression with parantheses: ");
    scanf("%s", str);
    InitializeStack(&s);
    while(str[i]!='\0'){
    if(str[i]>='0'&&str[i]<='9')
    strncat(PFstring,&str[i],1);
    else if(str[i]='(')
    Push(&s,str[i]);
    else if(str[i]=')'){
    Pop(&s,&a);
    while(a!='('){
    strncat(PFstring,&a,1);
    Pop(&s,&a);
    }
    }
    else if(!EmptyStack(&s)){
    Pop(&s,&a);
    switch(str[i]){
    case'-':
    case'+':if(a=='(')
    Push(&s,a);
    else
    strncat(PFstring,&a,1);
    break;
    case'*':
    case'/':if(a=='+'||a=='-'||a=='(')
    Push(&s,a);
    else
    strncat(PFstring,&a,1);
    break;
    case'^':if(a=='^')
    strncat(PFstring,&a,1);
    else
    Push(&s,a);
    break;
    }
    Push(&s,str[1]);
    }
    i++;
    }
    while(!EmptyStack(&s)){
    Pop(&s,&a);
    strncat(PFstring,&a,1);
    }
    printf("The postfix expression is %s\n", PFstring);
    }

    Its only a portion of the program.I didnt include the function declaration but the prototype.The error i keep on getting is cannot convert from int* to char*.How do I change the code without changing the structure of my stack functions?I can affort to change the stack functions cause it will cause problem in my other functions.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Ung.... this is tough. I would normally suggest just writing up a different stack function to handle chars, but the following MAY work...
    Code:
    Pop(&s,&(int)a);
    or...
    Code:
    Pop(&s, (int *) &a);
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 07:44 AM
  2. converting infix to postfix
    By rainman39393 in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2008, 07:24 AM
  3. Replies: 4
    Last Post: 03-12-2006, 02:17 PM
  4. Converting from infix to postfix
    By jcramer in forum C Programming
    Replies: 4
    Last Post: 03-27-2004, 09:23 PM
  5. Infix to Postfix
    By dat in forum C Programming
    Replies: 6
    Last Post: 06-16-2003, 08:46 AM