- 1
for this program it's not possible to input the expression.. how?
#include <iostream> #include<string.h> #define ss 50 using namespace std; void push(int item,int *top,char s[]) { if(*top==ss-1) {cout<<"overflow"; return ;} s[++*top]=item; } char pop(int *top,char s[]) { if(*top==-1) { return 0;} char id=s[(*top)--]; return id; } int g(char sym) { switch (sym ) { case '+' : case '-': return 1; case '*': case '/': return 3; case '^' : case '
#x27;: return 6; case '(': return 9; case ')': return 0; default : return 7; } } int f(char sym) { switch (sym ) { case '+' : case '-': return 2; case '*': case '/': return 4; case '^' : case '#x27;: return 5; case '(': return 0; case '#': return -1; default : return 8; } } void ip(char in[],char p[]) { int top,i,j; char s[20] ,sym; top=-1; push('#',&top,s); j=0; for (i=0;i<strlen(in);i++) { sym=in[i] ; while (f(s[top])>g(sym)) { p[j] =pop(&top,s); j++; } if(f(s[top])!=g(sym)) push(sym,&top,s); else pop(&top,s); } while (s[top]!='#') { p[j++] =pop(&top,s); p[j]='\0'; } } int main() { char in[20],p[20]; int i; cout<<"giv a valid expn\n"; for(i=0;i<'\0';i++) cin>>in[i]; ip(in,p); cout<<"converted postfix expn\n"; for(i=0;i<'\0';i++) cout<<p[i]; return 0; }1 Answer
0
I believe that there's a problem with the for loop in your main function. I think i<'\0' isn't a valid condition. Correct me if I'm wrong