-4

I implement the shunting yard algorithm. When I run the program the error "The expression must have a constant value" comes out. How do I get the value of the length variable into the correct form?

int length = infix.length();
char input[length +1];
strcpy(input, infix.c_str());

The error appears here: char input[length +1];

Don Diablo
  • 31
  • 5

1 Answers1

-2

In order to let the compiler know the size of an array allocated in the stack (like you've done) the value in the size of the array must be known during compile time. Therefore, you must have a size which is not define during the run.

The size of the array should be something bigger enough like:

char input[1024];

Or allocate it on the heap:

char* input = new char[length + 1];