rendered paste body#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Item.h"
#include "STACK.h"
#define MAX 100000000
/*Priorities and dec values:
+ 1 //43
- 1 //45
* 2 //42
/ 2 //47
^ 3 //94
@ 4 //64
*/
char string[MAX];
char a[MAX];
int main(int argc, char *argv[]){
//char *a = argv[1];
char c;// comment
int i=0; //counter
int j=0; //counter
int N=0;
char temp=0;
while((c = getchar()) != EOF){
a[i]=c;
i++;
}
N = strlen(a);
STACKinit(N);
//char string[MAX];
//Infix-to-postfix conversion
for(i=0;i<N;i++){
if(a[i]==')'){
string[j]=STACKpop();
j++;
}
if(a[i]=='-'){
temp=STACKpop(a[i]);
STACKpush(temp);
printf("minus temp is: %c\n",temp);
while ((temp=='*')||(temp=='/')||(temp=='^')||(temp=='@')||(temp=='-')||(temp=='+')){
printf("before popping: %c\n",temp);
temp=STACKpop(a[i]);
printf("after popping: %c\n",temp);
string[j]=temp;
j++;
string[j]=' ';
j++;
}
STACKpush(a[i]);
printf("pushing: %c\n",a[i]);
}
if(a[i]=='+'){
temp=STACKpop(a[i]);
STACKpush(temp);
printf("plus temp: %c\n",temp);
while ((temp=='*')||(temp=='/')||(temp=='^')||(temp=='@')||(temp=='-')||(temp=='+')){
printf("plus popping: %c\n",temp);
temp=STACKpop(a[i]);
printf("been popped: %c\n",temp);
string[j]=temp;
j++;
string[j]=' ';
j++;
}
STACKpush(a[i]);
printf("pushing: %c\n",a[i]);
}
if(a[i]=='*'){
temp=STACKpop(a[i]);
STACKpush(temp);
while ((temp=='/')||(temp=='^')||(temp=='@')){ //might need to take out that '/'
temp=STACKpop(a[i]);
printf("times!!! popping: %c\n",temp);
string[j]=temp;
j++;
string[j]=' ';
j++;
}
STACKpush(a[i]);
printf("pushing: %c\n",a[i]);
}
if(a[i]=='/'){
temp=STACKpop(a[i]);
STACKpush(temp);
while ((temp=='^')||(temp=='@')){
temp=STACKpop(a[i]);
string[j]=temp;
j++;
string[j]=' ';
j++;
}
STACKpush(a[i]);
}
if(a[i]=='^'){
temp=STACKpop(a[i]);
STACKpush(temp);
while (temp=='@'){
temp=STACKpop(a[i]);
string[j]=temp;
j++;
string[j]=' ';
j++;
}
STACKpush(a[i]);
}
if(a[i]=='@'){
temp=STACKpop(a[i]);
STACKpush(temp);
STACKpush(a[i]);
string[j]=temp;
j++;
string[j]=' ';
j++;
}
if((a[i]>='0')&&(a[i] <='9')){
string[j]=a[i];
j++;
string[j]=' ';
j++;
}
// printf("the last temp is: %c\n",temp);
//string[j]='\0';
}
temp=STACKpop(a[i]);
STACKpush(temp);
printf("last temp is: %c\n",temp);
string[j]=temp;
j++;
string[j]='\0';
printf("\n");
printf("the converted string is: %s\n",string);
printf("the other string is: %s\n",a);
/*
//Postfix-expression evaluation
N=strlen(string);
STACKinit(N);
for (i = 0; i < N; i++){
if (string[i] == '+'){
STACKpush(STACKpop()+STACKpop());
}
if (string[i] == '*'){
STACKpush(STACKpop()*STACKpop());
}
//
if (string[i] == '^'){
STACKpush(STACKpop()*STACKpop());
}
if (string[i] == '@'){
STACKpush(STACKpop()*STACKpop());
}
if (string[i] == '-'){
STACKpush(STACKpop()+STACKpop());
}
//
if ((string[i] >= '0') && (string[i] <= '9')){
STACKpush(string[i]-'0');
}
// while ((string[i] >= '0') && (string[i] <= '9')){
// STACKpush(10*STACKpop() + (string[i++]-'0'));
// j++;
// }
}
printf("%d \n", STACKpop());
*/
return 0;
}