1 / 2
Jun 2019
indent preformatted text by 4 spaces

#include <stdio.h>
#include<stdlib.h>
#include <string.h>
void rpn(chartext)
{static int j=0;
char st[10];
char str[80]="";
int i;
char k;
int n=strlen(text);
for(i=0;i<n;i++)
{printf(“enter\n”);
if(text[i]=="(")
{
continue;
}
else if(text[i]==’+’||text[i]==’
’||text[i]==’-’||text[i]==’/’||text[i]==’^’)
{
st[j]=text[i];
printf("%c\n",st[j]);
j++;
}
else if(text[i]==’)’)
{
k=st[j];
strcat(str,k);
printf("%c\n",str);
j–;
}
else
{
printf(“yay\n”);
k=text[i];
strcat(str,k);
//strcat(str,’\0’);
printf("%c\n",str);
}
}
if(st[j]!=“null”)
{int k;
for(k=j;k>=0;k–)
{
strcat(str,st[j]);
}
}

}
int main()
{
printf(“find ex\n”);
char texts[]="((a+t)*((b+(a+c))^(c+d)))";
rpn(texts);
return 0;
}

  • created

    Jun '19
  • last reply

    Jun '19
  • 1

    reply

  • 647

    views

  • 2

    users

  • 1

    link

Your code doesn’t compile. I can try to fix the compilation errors, but then I can no longer be sure I’m running the same code as you. It’d be much better if you would edit your post, indent all the code, then repost it. This will cause the code to be treated as preformatted text, and so preserve things like indentation, asterisks etc.

That said, I think that st[10] is getting a buffer overflow because the expression is longer than 10 characters.

Is this for problem ONP2?