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

Home Posts Topics Members FAQ

can anyone find why is this program to solve postfix expression giving runtime error

48 New Member
#include<stdio.h>
#include<stdlib.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,k;
char a[100],c[100];
scanf("%d",&m);
for(i=0;i<m;i++)
{ int j=0;

while(1)
{

scanf("%c",&a[j]);
if(a[j]=='?')
break;
else if(a[j]==' ')
{
push(atoi(a));
j=0;
}
else if(a[j]=='+'||'-'||'*'||'/')
pop(a[j]);
else
j++;
}
printf("%d",s.n[s.top]);

}

}
Feb 3 '15 #1
1 1162
weaknessforcats
9,208 Recognized Expert Moderator Expert
This sort of thing is common in software development. It is a signal for you to step through your code using your debugger. If you don't know how to use it, then this is a great opportunity to learn how.

All I could do is do your debugging for you but this would be a disservice since I would rob you of a learning opportunity.
Feb 3 '15 #2

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

Similar topics

2
5927
by: fanfromfla | last post by:
I am using a database that has worked for many years for a holiday project for needy families. My organization recently upgraded its server and changed everyone to Windows XP. I just mention that...
2
2125
by: Massimo Soricetti | last post by:
Hello, I'm trying to fix this little class: <code> #include <ifstream> #include <iostream> #include <iomanip> using namespace std;
0
1783
by: royal | last post by:
This problem is to simulate an airport landing and takeoff pattern. The airport has 3 runways, runway 1, runway 2 and runway 3. There are 4 landing holding patterns, two for each of the first two...
6
13571
by: OldBirdman | last post by:
I've spent all day on this, and can't see what I'm doing wrong. I've Googled and all I find have the same mistake, using .Text when they should use .Value. In this case, .Text is correct. ...
3
2368
by: razjafry | last post by:
Hi, I am trying to create a combo box to search record on the base of ID but it gives runtime error message 2501 "the openform action was cancelled" all the times. I posted this question before but...
1
1157
by: gagonm | last post by:
Hi I had security audit of my applications. I have two applications 1) .NET 1.0 2) .NET 1.1 Here Request is sent in either form of https://DNSName:443/virtualdir/~default.aspx...
1
3524
by: b singh | last post by:
In iis 7 http:/site/x.aspx/pp%3f is giving runtime error Instaed of invalid virtual path. x.aspx is not existing in the server. What setting of IIS 7 is reuired so that it will give invalid...
1
1406
by: karthik mca | last post by:
rs3.Move (Index) rs3!a_Votes = Val(Text2(Index).Text) + 1 rs3.Update here index is working... dont bother about that... but this is not working.. can any one edit this code???? it is...
1
1318
by: krishhy | last post by:
I am trying to add data to my database using adodc my database is in ms access 2000-2003 but when i run my program its showing an error empty record-set cannot be added,and automatically ends the...
0
7051
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
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3003
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
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1307
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
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
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.