i 've done this code for converting a normal entry by user into rpn ,however this case doesn't work
1+(2+3)/5->1235/++ which gives wrong answer
the code is as follows:
and thanks in advance;
1+(2+3)/5->1235/++ which gives wrong answer
the code is as follows:
Code:
#include"stdlib.h" #include"stdio.h" #include"conio.h" #include"string.h" void main() { char n[20][100]={""}; char o[100]={""}; char c[100]; gets(o); strcpy(c,o); char* p=NULL; int i=0,j=0,len=strlen(o); char sep[]="()+-*/"; p=strtok (o,sep); while(p!=NULL) { strcpy(n[i],p); p=strtok (NULL,sep); i++; } j=len-1; while(c[j]!=NULL) { if(c[j]!=' ') { switch(c[j]) { case'+':{strcpy(n[i],"+");i++;break;} case'-':{strcpy(n[i],"-");i++;break;} case'*':{strcpy(n[i],"*");i++;break;} case'/':{strcpy([i],"/");i++;break;} default:break; } } j--; } for(j=0;j<20;j++) { printf("%s",n[j]); } }
Comment