473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

#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 1084
weaknessforcats
9,208 Expert Mod 8TB
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
But the program is not even running .main function is also not getting executed
Jan 31 '15 #3
weaknessforcats
9,208 Expert Mod 8TB
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
for(i=0;i<m;i++) is not getting executed but why?
Jan 31 '15 #5
weaknessforcats
9,208 Expert Mod 8TB
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
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,...

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.