can somebody help me bout this?
Code:void postfix() { stack *A; char a[100]; int a; clrscr(); create_stack(A); p("Enter a postfix expression: "); s("%s",&a) for(x=0;x<strlen(a);x++) {if(x[a]>='0'&&x[a]<='9') push(A,a[x]); else pop(A); }
can somebody help me bout this?
Code:void postfix() { stack *A; char a[100]; int a; clrscr(); create_stack(A); p("Enter a postfix expression: "); s("%s",&a) for(x=0;x<strlen(a);x++) {if(x[a]>='0'&&x[a]<='9') push(A,a[x]); else pop(A); }
Looks like a function to me that calls other functions.
So what help do you want?
I think you should lose the pointless
#define p printf
#define s scanf
macros.
You also have two variables with the same name.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ah ok... tnx.. but we have a problem in evaluating the expression
Code:void postfix() { stack *A; stack *B; stack *C; stack *D; char a[100]; char b; char *c; int x,f,d,e,g,h,i; clrscr(); create_stack(A); create_stack(B); create_stack(C); create_stack(D); printf("Enter a postfix expression: "); scanf("%s",a); for(x=0;x<strlen(a);x++) {if(a[x]>='0' && a[x]<='9') { push(A,a[x]); *c=pop(A); b=atoi(c); push(B,b); } else if(a[x]=='-') { e=pop(B); d=pop(B); f=e-d; push(C,f); h=pop(C); } } printf("Result: %d",i); getch(); }
Can you please describe what the problem is that you are struggling with?
It's all well and good reading your code and coming up with POTENTIALLY broken bits, but seriously, we need to understand what it is that you can't solve. What is your input, and what does it output, and how is that different from what you expected?
--
Mats
> create_stack(A);
Is this a function, or a macro?
Because if it's a function, then it's highly unlikely that you're actually initialising the stack, just a copy of it which is lost when the function returns.
Also, pick more meaningful names for your variables. i is OK for a loop variable, but everything else should have at least some meaning.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.