I have created a program that loads an expression from an input file and converts the expression from infix to postfix form.
So in the file I have expressions. Each expression is placed on a separate line in the text file. I read from the file line by line and form a array of strings that make up the expressions from the text file. I take each string from the array and convert it to postfix form.
The problem is that when converting from infix to postfix, I print out the characters. The array of strings from the input is not changed.
Here' s code:
for(i = 0; i < strlen(c); i++)
{
if(c[i] == '(')
stek.arr[++stek.tos] = '(';
else if(c[i] == ')')
{
while(stek.arr[stek.tos] != '(')
{
printf("%c", stek.arr[stek.tos--]);
}
stek.tos--;
}
// if Operator
else if(isOperator(c[i]))
{
while(stek.tos != -1 && !isHigherPrecedence(c[i], stek.arr[stek.tos]))
{
printf("%c", stek.arr[stek.tos--]);
}
stek.arr[++stek.tos] = c[i];
}
// if operand
else
{
printf("%c", c[i]);
}
}
while(stek.tos != -1)
{
printf("%c", stek.arr[stek.tos--]);
}
This is just the conversion code from infix to postfix form.
c-represents a string of expressions loaded from a file, it is at the beginning a string of the first line, a string of the second line, etc.
My question is : When a string is converted from infix to postfix form, it is printed character by character. How to create a new array of strings that will contain only the postfix form?
I want these characters that are printed individually in this code to be put into an array, and it becomes an array of strings.