int main() { int numberOfTestCase,i; scanf("%d",&numberOfTestCase); getchar(); char **values = (char **)malloc(numberOfTestCase*sizeof(char *)); for(i=0;i<numberOfTestCase;i++) { values[i] = (char *)malloc(1000*sizeof(char)); } //char values[numberOfTestCase][1000]; for(i=0;i<numberOfTestCase;i++) { scanf("%s",values[i]); } char **res; res=braces(numberOfTestCase,values,numberOfTestCase); for(i=0;i<numberOfTestCase;i++) { puts(res[i]); } /*for (i = 0; i < numberOfTestCase; i++) { char* currentIntPtr = values[i]; char* currentIntPtr1 = res[i]; free(currentIntPtr); free(currentIntPtr1); }*/ return 1; }
int main() { int i , j=0 , chk ; int popped , pre , prep; char ele , elem; strcpy(postfix," "); printf("\nEnter the infix expression :"); gets(infix); chk = braces(infix); if(chk!=0) { printf("\nUnbalanced no. of braces"); printf("\n Extra %s" , (chk==1 ? "right bracrs" : "left braces")); getch(); exit(1); } for(i=0 ; infix[i]!='\0' ; i++) { if(infix[i]!='(' &&infix[i]!=')' &&infix[i]!='/' &&infix[i]!='*' &&infix[i]!='+' &&infix[i]!='-' && infix[i]!='^') postfix[j++]=infix[i]; else if(infix[i]=='(') { elem= infix[i]; push(elem); } else if(infix[i]==')') { while((popped=pop())!='(') postfix[j++] = popped; } else { elem=infix[i]; pre=precedence(elem); ele=topelement(); prep=precedence(ele); if(pre>prep) push(elem); else { while(prep>=pre) { if(ele=='#') break; popped=pop(); postfix[j++]=popped; ele=topelement(); prep=precedence(ele); } push(elem); } } } while((popped=pop())!='#') postfix[j++] = popped; postfix[j]='\0'; printf("\nThe postfix expression is : "); puts(postfix); return 0; }