473,513 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i overcome Stack Exception processor fault in ths program........?

1 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. void main()
  4. {
  5. char istr[100],tstack[100],ostr[100];
  6. int i=0,top=0,j=0;
  7. printf("Enter the infix expression...\n");
  8. scanf("%s",&istr);
  9. printf("The infix expression is :%s\n",istr);
  10. while(istr[i]!='\0')
  11. {
  12. switch(istr[i])
  13. {
  14. case '^':
  15. case '%':
  16. case '/':
  17. case '*':
  18.             if(tstack[top]=='+'||tstack[top]=='-'||tstack[top]=='(')
  19.             {
  20.             top++;
  21.             tstack[top]=istr[i];
  22.             }
  23.             else if(tstack[top]=='\0')
  24.             tstack[top]=istr[i];
  25.             else
  26.             {
  27.             while(tstack[top]!='\0')
  28.             {
  29.             ostr[j]=tstack[top];
  30.             top--;
  31.             j++;
  32.             }
  33.             if(top==-1)
  34.             top++;
  35.             tstack[top]=istr[i];
  36.             }
  37.             break;
  38. case '+':
  39. case '-':
  40.             if(tstack[top]=='(')
  41.             {
  42.             top++;
  43.             tstack[top]=istr[i];
  44.             }
  45.          else if(tstack[top]=='\0')
  46.             tstack[top]=istr[i];
  47.             else
  48.             {
  49.             while(tstack[top]!='\0')
  50.             {
  51.             ostr[j]=tstack[top];
  52.             top--;
  53.          j++;
  54.             }
  55.             if(top==-1)
  56.             top++;
  57.             tstack[top]=istr[i];
  58.             }
  59.             break;
  60. case '(':if(tstack[top]=='\0')
  61.             tstack[top]=istr[i];
  62.             else
  63.             {
  64.             top++;
  65.             tstack[top]=istr[i];
  66.             }
  67.             break;
  68. case ')':while(tstack[top]!='(')
  69.             {
  70.             ostr[j]=tstack[top];
  71.             top--;
  72.             j++;
  73.             }
  74.             tstack[top]='\0';
  75.             top--;
  76.             break;
  77. default :ostr[j]=istr[i];
  78.             j++;
  79.             break;
  80. }
  81. i++;
  82. }
  83. while(top!=-1)
  84. {
  85. ostr[j]=tstack[top];
  86. top--;
  87. j++;
  88. }
  89. printf("The postfix expression is :%s",ostr);
  90. }
Apr 23 '15 #1
2 1452
zmbd
5,501 Recognized Expert Moderator Expert
We do not have your data nor CPU to compile and run so:
What troubleshooting, if any, have you already done?
What is the error code you are receiving - several reasons for stack exceptions?
At what line is your code faulting?
Apr 23 '15 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
The first thing I notice is all the arrays are 100 elements but nowhere in the code is there a check to see if top++, i++, or j++ goes over 99. Also, top--is never checked to see a negative value occurs.

This is an excellent time to use your debugger and step through the code.
Apr 23 '15 #3

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

Similar topics

0
891
by: Jon Perez | last post by:
I have a script that takes command-line arguments which I want to debug using pdb upon an unanticipated exception. How do I go about doing this? If I do a "c:\python23\lib\pdb.py script.py blah...
7
2178
by: damacy | last post by:
hi, there. i have this question which might sound quite stupid to some people, but here we go anyway. i have written a python program which interacts with a postgresql database. what it does is...
0
1002
by: fdu.xiaojf | last post by:
Hi, When I want to uninstall my usb disk on windows, the operating systems sometimes tells me the device is being used by other program. But I can't find which program is using it. Can I do this...
0
1564
by: Jeff | last post by:
..NET 2.0 While debugging a win service a message appear with the text "Pass exception on to program being debugged?" (yes/no buttons) on this C# line: int b = 6; I click on the no button and...
2
2096
by: jimhakans | last post by:
#include<stdio.h> main() { int mark,j,i; for(j=0;j<25;j++) { for(i=0;i<4;i++) { printf("\nEnter you marks\n"); scanf("%d",marks);
3
1498
underscore
by: underscore | last post by:
To all TSDN am here again to ask your assistance about this problem in updating my project. I have a project ROOM RESERVATION and in my 'setuproom.php' theres a table display of all room names...
4
2349
by: khan | last post by:
Hi I am in need to write a function which prints the stack trace of current program The need is that if any exception occurs then apart from error message we want to print the stack trace of...
15
2653
by: danielo | last post by:
class Error { Error(string err) { cout << err; } } void main() { try { throw string("exception"); } catch(Error Err) {
10
9432
by: rusty uts | last post by:
Well I had an assignment to sort an array of structures so i went about trying but always some strange fault come about. Now not only does the main program fail but also another program. What i want...
0
7267
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
7175
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...
0
7391
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
7553
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
7542
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
4754
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
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
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.