943,962 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 19395
  • C++ RSS
May 9th, 2007
0

Help pplz. . convert infix to postfix. .

Expand Post »
Hi. . can any one help me in converting infix to postfix. . i do not know what is wrong in my code. . help!!!plz
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<string>
  3. #include<conio.h>
  4. #include<stdio.h>
  5. using namespace std;
  6. void main()
  7. {
  8. char stack[10];
  9. char input[10];
  10. char output[10];
  11. char plusminus,multdiv;
  12. int a;
  13. cout<<"\tInput an infix expression:";
  14. gets(input);
  15. int i;
  16. i=strlen(input);
  17. cout<<strlen(input);
  18. for(a=0;a<=i;a++){
  19. if(input[a]>='a'&&input[a]<='z'){
  20.  
  21. output[a]=input[a];
  22. }
  23. else if(input[a]=='+'||input[a]=='-'){
  24. plusminus=input[a];
  25. }
  26. else if(input[a]=='*'||input[a]=='/'){
  27. multdiv=input[a];
  28. }
  29. if(input[a]==plusminus){
  30. stack[a]=input[a];
  31. if(stack[a]==plusminus&&stack[a+1]==plusminus){
  32. output[a]=stack[a];
  33. }
  34. }
  35. else if(input[a]==multdiv){
  36. stack[a]=input[a];
  37. if(stack[a]==multdiv&&stack[a+1]==multdiv){
  38. output[a]=stack[a];
  39. }
  40. }
  41. }
  42. cout<<"\tPostfix Expression :"<<output<<"\n";
  43. }
Last edited by Narue; May 9th, 2007 at 10:05 am. Reason: Added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Madzts is offline Offline
7 posts
since Apr 2007
May 9th, 2007
1

Re: Help pplz. . convert infix to postfix. .

First of all add code tags. Find out why void main and gets are bad. There is many posts about them.
Last edited by andor; May 9th, 2007 at 9:02 am. Reason: Corecting "add code tags" to "First of all add code tags"
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
May 9th, 2007
0

Re: Help pplz. . convert infix to postfix. .

Yes void main, gets (you're using c++ so no need for them anyway) conio.h all wrong and/or unnecessary.

http://www.daniweb.com/code/snippet599.html

See there for ideas.
Last edited by iamthwee; May 9th, 2007 at 2:27 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 10th, 2007
0

Re: Help pplz. . convert infix to postfix. .

Click to Expand / Collapse  Quote originally posted by Madzts ...
Hi. . can any one help me in converting infix to postfix. . i do not know what is wrong in my code. . help!!!plz
Neither do we, you didn't tell us what it's doing wrong, nor what it does right. We need information to understand the problem.

And check the following links to see what is wrong with gets() and void main()
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is online now Online
7,744 posts
since May 2006
Oct 19th, 2009
-1

Conversion of infix expression to postfix using stacks (simple C++ Program)

Friends plz help me to write simple c++ program just to convert infix expression to postfix expression using stacks, i don't know abt C++ too much, just write a simple c++ program, i have to submit my assignment, mail me at: SNIP
Last edited by happygeek; Oct 19th, 2009 at 6:42 pm. Reason: email snipped
Reputation Points: 9
Solved Threads: 0
Newbie Poster
Afaq Haider is offline Offline
2 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: multiple forms
Next Thread in C++ Forum Timeline: C-String reverse





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC