I am working on a small C application and I am capturing a value from the command line. I would like to capture the value and use it to initialize an array. Here is what I’m trying to do.
int main(int argc, char* argv[]) {
int option = atoi(argv[2]);
int values[option];
......
}
I am getting a compilation because my option variable is not a const.
Error: Error 2 error C2057: expected constant expression
Is there a way I can do this?
Thanks for your help!
If the size is not known at compile-time, you need to allocate the memory dynamically, with
malloc: