The compiler give me this error:
debug assertion failed!!
This is my code:
#include "stdafx.h"
# include <iostream>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
using namespace std;
int top=-1;
char Stack[25][100]={NULL};
void push(const char *);
const char* pop( );
void postfix_to_infix(const char *);
int main( )
{
char Postfix_expression[100]={NULL};
cout<<"\n\n\t Enter the Postfix Expression : ";
cin.getline(Postfix_expression,80);
postfix_to_infix(Postfix_expression);
_getch( );
}
void push(const char *Symbol)
{
if(top==24)
cout<<"Error : Stack is full."<<endl;
else
{
top++;
strcpy_s(Stack[top],Symbol);
}
}
const char* pop( )
{
char Symbol[100]={NULL};
if(top==-1)
cout<<"Error : Stack is empty."<<endl;
else
{
strcpy_s(Symbol,Stack[top]);
_strset_s(Stack[top],NULL);
top--;
}
return Symbol;
}
void postfix_to_infix(const char *Postfix)
{
char Infix_expression[100]={NULL};
char Postfix_expression[100]={NULL};
strcpy_s(Postfix_expression,Postfix);
strcat_s(Postfix_expression,"=");
int count=0;
char Symbol_scanned[5]={NULL};
do
{
Symbol_scanned[0]=Postfix_expression[count];
if(Symbol_scanned[0]=='/' || Symbol_scanned[0]=='*' ||
Symbol_scanned[0]=='-' || Symbol_scanned[0]=='+' ||
Symbol_scanned[0]=='^' )
{
char Value_1[100]={NULL};
char Value_2[100]={NULL};
char Result[100]={NULL};
strcpy_s(Value_1,pop( ));
strcpy_s(Value_2,pop( ));
if(Infix_expression[(count+1)]!='=')
strcpy_s(Result,"(");
strcat_s(Result,Value_2);
strcat_s(Result,Symbol_scanned);
strcat_s(Result,Value_1);
if(Infix_expression[(count+1)]!='=')
strcat_s(Result,")");
push(Result);
}
else
push(Symbol_scanned);
count++;
}
while(Postfix_expression[count]!='=');
_strset_s(Infix_expression,NULL);
strcpy_s(Infix_expression,pop( ));
cout<<"\n\n\t Infix Expression is : "<<Infix_expression;
}