#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<string.h>
#define max 100
Void push(char);
Char pop();
Int *p;
Int *tos;
Int *bos;
Char i;
Void push(char)
{
If(p>bos)
{
Printf(\n stack is full.);
Return;
}
*p=i;
P++;
}
Char pop()
{
P--;
If(p<tos)
{
Printf(\n stack is empty);
Getch();
Return 0;
}
Return *p;
}
Int main()
Char s[80],b[80],x,y;
Int j;
P=(int*)malloc(max *sizeof(int));
If(!p)
{
Printf(\n allocation failure);
Exit(1);
}
Tos =p;
Bos=p+max-1;
Clrscr();
Printf(\n enter postfix expression:);
Gets(s);
For(j=0;j<80;j++)
{
Do
{
If(s[j]==+ ||s[j]==-||s[j]==*||s[j]==/||s[j]==^)
{
Y=pop();
X=pop();
Strcat(&x,&y);
Strcat(&s[j],&x);
Push(s[j]);
}
Else
{
Push(s[j]);
}
B[80]=pop();
}
While(s[j]!=\0);
}
Printf(\n the prefix expression is:);
Puts(B)/>/>;
Getch();
Return 0;
}
problem in execute of postfix to prefix
Page 1 of 110 Replies - 189 Views - Last Post: 29 December 2012 - 12:23 PM
#1
problem in execute of postfix to prefix
Posted 29 December 2012 - 06:17 AM
Sorry I dont speak English very well but I need to help me to execute this program about the conversation postfix to prefix expression. after the execute in turbo c ++ and enter the postfix expression ,the program dont work and I dont know where is problem in my program because dont give me eror or warning . i want to find the problem of program to repair it
Replies To: problem in execute of postfix to prefix
#2
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 06:35 AM
Quote
dont give me eror or warning
How could you even say that?
Look at your code, C is case-sensitive and you have messed up every single keyword and statement...
Fix your code, printf() is different than Printf() similarly the rest of the code...
Also, stop using turbo-c, use a recent compiler that is compliant with the standards. Like gcc...
#3
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 06:46 AM
i was typed my program in word and paste it in this site and in turbo program was typed in minuscule alphabet and realy dont give me error and it executed . just dont give me prefix expression and after the enter ,it went to after line without doing any work
#4
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 07:22 AM
Do you mean you typed this one in Ms-Word and the real code is different?
Please post your real code...
Please post your real code...
#5
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 07:29 AM
Also never use a word processor with C/C++ source code files. These programs many times will put formatting characters in your source that the compiler will not understand.
Jim
Jim
#6
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 09:26 AM
this is real code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<string.h>
#define max 100
void push(char);
char pop();
int *p;
int *tos;
int *bos;
char i;
void push(char)
{
if(p>bos)
{
printf(\n stack is full.);
return;
}
*p=i;
p++;
}
char pop()
{
p--;
if(p<tos)
{
printf(\n stack is empty);
getch();
return 0;
}
return *p;
}
int main()
char s[80],b[80],x,y;
int j;
p=(int*)malloc(max *sizeof(int));
if(!p)
{
printf(\n allocation failure);
exit(1);
}
tos =p;
bos=p+max-1;
clrscr();
printf(\n enter postfix expression:);
gets(s);
for(j=0;j<80;j++)
{
do
{
if(s[j]==+ ||s[j]==-||s[j]==*||s[j]==/||s[j]==^)
{
y=pop();
x=pop();
strcat(&x,&y);
strcat(&s[j],&x);
push(s[j]);
}
else
{
push(s[j]);
}
b[80]=pop();
}
while(s[j]!=\0);
}
printf(\n the prefix expression is:);
puts(B)/>/>;
getch();
return 0;
}
#7
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 09:36 AM
That "real" code has many problems caused by using your word processor.
All the "stray" errors are being caused because your word processor used different quotes. Lets look at the first one.
Both the starting quote and ending quote are wrong you need to erase them and retype the proper quote ".
Fix these errors then properly indent your code and if you are still having problems re-post the modified code and the complete error messages.
Jim
Quote
main.c||In function push:|
main.c|12|error: parameter name omitted|
main.c|16|error: stray \342 in program|
main.c|16|error: stray \200 in program|
main.c|16|error: stray \234 in program|
main.c|16|error: stray \ in program|
main.c|16|error: n undeclared (first use in this function)|
main.c|16|note: each undeclared identifier is reported only once for each function it appears in|
main.c|16|error: expected ) before stack|
main.c|16|error: stray \342 in program|
main.c|16|error: stray \200 in program|
main.c|16|error: stray \235 in program|
main.c||In function pop:|
main.c|27|error: stray \342 in program|
main.c|27|error: stray \200 in program|
main.c|27|error: stray \234 in program|
main.c|27|error: stray \ in program|
main.c|27|error: n undeclared (first use in this function)|
main.c|27|error: expected ) before stack|
main.c|27|error: stray \342 in program|
main.c|27|error: stray \200 in program|
main.c|27|error: stray \235 in program|
main.c||In function main:|
main.c|36|error: expected declaration specifiers before p|
main.c|37|error: expected declaration specifiers before if|
main.c|39|error: stray \342 in program|
main.c|39|error: stray \200 in program|
main.c|39|error: stray \234 in program|
main.c|39|error: stray \ in program|
main.c|39|error: stray \342 in program|
main.c|39|error: stray \200 in program|
main.c|39|error: stray \235 in program|
main.c|42|error: expected declaration specifiers before tos|
main.c|43|error: expected declaration specifiers before bos|
main.c|44|error: expected declaration specifiers before clrscr|
main.c|45|error: expected declaration specifiers before printf|
main.c|45|error: stray \342 in program|
main.c|45|error: stray \200 in program|
main.c|45|error: stray \234 in program|
main.c|45|error: stray \ in program|
main.c|45|error: stray \342 in program|
main.c|45|error: stray \200 in program|
main.c|45|error: stray \235 in program|
main.c|46|error: expected declaration specifiers before gets|
main.c|47|error: expected declaration specifiers before for|
main.c|47|error: expected declaration specifiers before j|
main.c|47|error: expected declaration specifiers before j|
main.c|51|error: stray \342 in program|
main.c|51|error: stray \200 in program|
main.c|51|error: stray \231 in program|
main.c|51|error: stray \342 in program|
main.c|51|error: stray \200 in program|
main.c|51|error: stray \231 in program|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|
main.c|12|error: parameter name omitted|
main.c|16|error: stray \342 in program|
main.c|16|error: stray \200 in program|
main.c|16|error: stray \234 in program|
main.c|16|error: stray \ in program|
main.c|16|error: n undeclared (first use in this function)|
main.c|16|note: each undeclared identifier is reported only once for each function it appears in|
main.c|16|error: expected ) before stack|
main.c|16|error: stray \342 in program|
main.c|16|error: stray \200 in program|
main.c|16|error: stray \235 in program|
main.c||In function pop:|
main.c|27|error: stray \342 in program|
main.c|27|error: stray \200 in program|
main.c|27|error: stray \234 in program|
main.c|27|error: stray \ in program|
main.c|27|error: n undeclared (first use in this function)|
main.c|27|error: expected ) before stack|
main.c|27|error: stray \342 in program|
main.c|27|error: stray \200 in program|
main.c|27|error: stray \235 in program|
main.c||In function main:|
main.c|36|error: expected declaration specifiers before p|
main.c|37|error: expected declaration specifiers before if|
main.c|39|error: stray \342 in program|
main.c|39|error: stray \200 in program|
main.c|39|error: stray \234 in program|
main.c|39|error: stray \ in program|
main.c|39|error: stray \342 in program|
main.c|39|error: stray \200 in program|
main.c|39|error: stray \235 in program|
main.c|42|error: expected declaration specifiers before tos|
main.c|43|error: expected declaration specifiers before bos|
main.c|44|error: expected declaration specifiers before clrscr|
main.c|45|error: expected declaration specifiers before printf|
main.c|45|error: stray \342 in program|
main.c|45|error: stray \200 in program|
main.c|45|error: stray \234 in program|
main.c|45|error: stray \ in program|
main.c|45|error: stray \342 in program|
main.c|45|error: stray \200 in program|
main.c|45|error: stray \235 in program|
main.c|46|error: expected declaration specifiers before gets|
main.c|47|error: expected declaration specifiers before for|
main.c|47|error: expected declaration specifiers before j|
main.c|47|error: expected declaration specifiers before j|
main.c|51|error: stray \342 in program|
main.c|51|error: stray \200 in program|
main.c|51|error: stray \231 in program|
main.c|51|error: stray \342 in program|
main.c|51|error: stray \200 in program|
main.c|51|error: stray \231 in program|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|
All the "stray" errors are being caused because your word processor used different quotes. Lets look at the first one.
printf(\n stack is full.);
Both the starting quote and ending quote are wrong you need to erase them and retype the proper quote ".
Fix these errors then properly indent your code and if you are still having problems re-post the modified code and the complete error messages.
Jim
#8
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 10:51 AM
Thank you very mush but idont enough time for repair my program and i got a program in another site but idont know where can I set getch() to see payoff
#include<stdio.h>
#include<string.h>
void push(char item[],int *top,char s[][20])
{
*top=*top+1;
strcpy(s[*top],item);
}
void *pop(int *top,char s[][20])
{
char *item;
item=s[*top];
*top=*top-1;
return item;
}
void pre_post(char prefix[],char postfix[])
{
char s[20][20];
int top,i;
char symbol,temp[2];
char *op1,*op2;
top=-1;
strrev(prefix);
for(i=0;i<strlen(prefix);i++)
{
symbol=prefix[i];
temp[0]=symbol;
temp[1]='\0';
switch (symbol)
{
case '+':
case '-':
case '*':
case '/':
case '^':
op1=pop(&top,s);
op2=pop(&top,s);
strcpy(postfix,op1);
strcat(postfix,op2);
strcat(postfix,temp);
push(postfix,&top,s);
break;
default:
push(temp,&top,s);
}
}
}
void main()
{
char prefix[20];
char postfix[20];
printf("\n\n Enter the prefix expression \n\n");
scanf("%s",prefix);
pre_post(prefix,postfix);
printf("\n\n The postfix expression is %s \n\n",postfix);
}
#9
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 11:02 AM
What good does it do you to "find" a solution. That won't help you become a programmer. You learn to program by programming not by copying some other persons work.
Jim
Jim
#10
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 11:29 AM
thanks i usually writing my program with php and i dont enough learning for c++ and c and i have to deliver this program tommorrow however thank you for everything
#11
Re: problem in execute of postfix to prefix
Posted 29 December 2012 - 12:23 PM
Here's your payoff: don't be a copy/paste cheater.
Closed.
Closed.
Page 1 of 1
|
|

New Topic/Question
This topic is locked



MultiQuote




|