473,473 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

can anyone tell why my program for solving postfix expression is not working

48 New Member
#include<stdio.h>
struct stack{
int top;
int n[100];
}s;
void push(int a)
{
s.n[s.top+1]=a;
s.top++;
}
void pop(char a)
{
int c,b;
b=s.n[s.top];
c=s.n[s.top-1];
s.top--;
switch(a)
{
case '+':
s.n[s.top]=b+c;
break;
case '-':
s.n[s.top]=b-c;
break;
case '*':
s.n[s.top]=b*c;
break;
case '/':
s.n[s.top]=b/c;
break;
}
}
int main()
{
s.top=-1;
int m,i,j,k;
char a[100],c[100];
scanf("%d",&m);
for(i=0;i<m;i++)
{
for(j=0;j<100;j++)
{
for(k=0;;k++)
{scanf("%c",&a[k]);
if(a[k]==' ')
break;
}
if(a[0]=='+'||'-'||'*'||'/')
pop(a[0]);
else if(a[0]=='?')
break;
else
push(atoi(a));
}
printf("%d",s.n[s.top]);
}
}
Jan 31 '15 #1
5 1086
weaknessforcats
9,208 Recognized Expert Moderator Expert
Have you stepped through your code using your debugger? If not, this is an excellent time to learn how. Having me debug your code isn't going to help you learn how to do it.
Jan 31 '15 #2
jinnejeevansai
48 New Member
But the program is not even running .main function is also not getting executed
Jan 31 '15 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
It's a problem if your code won't compile.

In this case you use atoi() but don't #include <stdlib.h>.

If your code compiles, main() will always execute
Jan 31 '15 #4
jinnejeevansai
48 New Member
for(i=0;i<m;i++) is not getting executed but why?
Jan 31 '15 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
It executes on my machine.

I inserted a breakpoint at the for loop and then selected "start debugging" on Visual Studio. The debugger stopped at that breakpoint.

Does your debugger not do the same thing?
Feb 1 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike | last post by:
Hi All, I am using a COM object and so I have to use a form for it to work. The problem is I need to run it as a service as well. When I run it in a test scenario everything works fine and...
3
by: Just Me | last post by:
I noticed that I don't get KeyDown nor KetPress events if NumLock is not on. I can probably find a workaround but it would be nice to know what the rules are. Can anyone tell me when KeyPress...
6
by: mismis | last post by:
HELP!..PLEASE..i have a project that asks to write a C++ program solving for the root of the equation (x*x*x)-(x*x)-(9x)+(9) ........huhuhu..please help..i really need to pass..please..
7
by: franklyn | last post by:
converting infix to postfix expression in 'c'
4
by: doc | last post by:
Anyone tell me about patServer please. Does anyone know where I can find instructions on how to use patServer - spent ages on the net trying to find a 'how to'. Specifically, where to put each...
2
by: rohit tripathi | last post by:
Write a program to evaluate a postfix expression using a stack. Note that 1. The expression may have the operators + - * / div and mod. 2. The expression may have variables and numbers...
1
by: sathishsolomon | last post by:
I wrote c program for evaluating postfix expression using stack.my program is running but i am getting output like stack overflow and the result is 0.what i should do to overcome this run-time...
5
by: nagmvs | last post by:
Can anyone tell me about the usage of split function in Asp with Example ? i done one project using split function.and i have some problems regarding storing data in data base.I use there...
1
by: maheshgupta0248 | last post by:
Hi everyone.. Im newbie in the driver development.. till now i have developed some drivers in Linux. Now I have to change to Windows.. can anyone tell me what are the real differences between driver...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.