Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Need Help Displaying of Infix to postfix conversion |
| Date | 2016-08-21 11:17 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <npbv3p$6fe$1@dont-email.me> (permalink) |
| References | <f3b33761-dc0c-4902-b8ce-e50f2c3430c9@googlegroups.com> |
On 21/08/2016 10:47, Own IT wrote:
> I have a program with me and it works fine, however I want a different output. The program is all about infix to postfix conversion. Say I have a expression of 3*7-5+6, my code displays 37*5-6+ which is correct however I want an output like this:
> 3
> 37
> 37*
> 37*5
> 37*5-
> 37*5-6
> 37*5-6+
This is just the final line, but output incrementally on each line? So
with ABC as the result, it is shown as:
A
AB
ABC
?
> char pop()
Use char pop(void) here. (Otherwise it won't work with some compilers.)
> int priority(char x)
> {
> if(x == '(')
> return 0;
> if(x == '+' || x == '-')
> return 1;
> if(x == '*' || x == '/')
> return 2;
> }
You need indents here on the return statements. Then you'll see there is
no return statement for when all conditions are false.
> while(top != -1)
> {
> printf("%c",pop());
> }
This is where you'll want to store each character into a array of
characters, rather than just output them immediately.
Once in such a string, then one or two loops and some logic will give
you the output you want. Note this will display all the lines at once;
you can't have a character-at-a-time output as you type the input, for
several reasons.
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Need Help Displaying of Infix to postfix conversion Own IT <beltondavid1@gmail.com> - 2016-08-21 02:47 -0700
Re: Need Help Displaying of Infix to postfix conversion BartC <bc@freeuk.com> - 2016-08-21 11:17 +0100
Re: Need Help Displaying of Infix to postfix conversion Keith Thompson <kst-u@mib.org> - 2016-08-21 15:43 -0700
Re: Need Help Displaying of Infix to postfix conversion BartC <bc@freeuk.com> - 2016-08-21 22:17 +0100
Re: Need Help Displaying of Infix to postfix conversion Keith Thompson <kst-u@mib.org> - 2016-08-21 18:17 -0700
Re: Need Help Displaying of Infix to postfix conversion Barry Schwarz <schwarzb@dqel.com> - 2016-08-21 09:42 -0700
Re: Need Help Displaying of Infix to postfix conversion Siri Cruise <chine.bleu@yahoo.com> - 2016-08-21 11:24 -0700
Re: Need Help Displaying of Infix to postfix conversion BartC <bc@freeuk.com> - 2016-08-21 23:40 +0100
Re: Need Help Displaying of Infix to postfix conversion Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-22 00:13 +0100
Re: Need Help Displaying of Infix to postfix conversion BartC <bc@freeuk.com> - 2016-08-22 01:31 +0100
Re: Need Help Displaying of Infix to postfix conversion David Kleinecke <dkleinecke@gmail.com> - 2016-08-21 20:13 -0700
Re: Need Help Displaying of Infix to postfix conversion supercat@casperkitty.com - 2016-08-22 09:44 -0700
Re: Need Help Displaying of Infix to postfix conversion Barry Schwarz <schwarzb@dqel.com> - 2016-08-22 10:18 -0700
Re: Need Help Displaying of Infix to postfix conversion supercat@casperkitty.com - 2016-08-22 10:27 -0700
Re: Need Help Displaying of Infix to postfix conversion "Osmium" <r124c4u102@comcast.net> - 2016-08-22 16:05 -0500
Usenet in general and CLC in particular (Was: Need Help something or other...) gazelle@shell.xmission.com (Kenny McCormack) - 2016-08-25 11:48 +0000
csiph-web