CFanatic

Go Back   CFanatic > Programming > C Programming

C Program to Convert Infix to Postfix topic posted under C Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2010, 10:36 AM
Junior Member
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
tamsy is on a distinguished road
| More
C Program to Convert Infix to Postfix

hey people please please please help me out with this. i have got my submission tommorrow and i have really worked hard on this i dont want it to turn out bad. this is a c program to convert infix expression to postfix without considering parentheses and already accepting that the given expression is a valid infix expression. what happens is the out is comin really weird.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int prece(char j);
void main()
{
	char infix[10],stack[5],output[10],j;
	int k=0,l=0,i,a,b;
	stack[k]=0;
	printf("write the infix expression to be converted to postfix");
	scanf("%s",infix);
	for(i=0;i<10;i++)
	{
		a=prece(infix[i]);
		b=prece(stack[k]);
		if(a<=b)
		{
			output[l]=infix[i];
			l++;
		}
		else
		{
			stack[k]=infix[i];
			k++;

		}
	}
	for(i=k;i>0;i--)
	{
		output[l]=stack[i];
		l++;
	}
	printf("%s",output);
	getch();
}
int prece(char j)
{
	if(j=='*'||j=='/')
	{
	   j=3;
	}
	else
	{
	    if(j=='+'||j=='-')
	    {
	       j=2;
	    }
	    else
	    {
	       j=1;
	    }
	}
	return j;
}
Reply With Quote
  #2  
Old 08-18-2010, 11:28 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,237
Thanks: 82
Thanked 76 Times in 49 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: c program to convert infix expression to postfix without considering parentheses

Reply With Quote
  #3  
Old 08-19-2010, 11:42 AM
Junior Member
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
tamsy is on a distinguished road
| More
Re: c program to convert infix expression to postfix without considering parentheses

hey thanks a lot !
Reply With Quote
  #4  
Old 08-19-2010, 11:39 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,237
Thanks: 82
Thanked 76 Times in 49 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: C Program to Convert Infix to Postfix

My Pleasure.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert string into integer nedo50 C Programming 1 09-05-2010 09:51 AM
how to convert files into .exe by c++ bumba819 C++ Programming 3 08-09-2010 10:24 AM
Convert infix notation to postfix notation. hkp819 C++ Programming 1 12-24-2008 11:16 PM
how to convert NFA to DFA in c ashokkumarrsp C Programming 3 07-31-2008 05:51 PM
convert dialog application rachel196 MFC Programming 1 06-26-2008 11:31 AM



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.