This gives an error because size is not set. Even if I initialize size at start up and then give it a value later on, array[size] will remain at the original value of size. I am trying to avoid declaring the char array after getting the info from the user. Dont ask me why but thats what I want to do. I believe it is possible but not sure. Thanks for any feed back.

Bitphire

02-26-2005

Thantos

Ignoring compiler extensions, array sizes must be known at compile time. Their is no standard method to make the array size based off of user input.

There are alternatives however:

make array a char * and after you get the size from the user use new[] to allocate the memory. Just remember to use delete[] to deallocate it.

You can also use a vector<char>. After you get the user's input call the resize member function to set the size.

Since you are dealing with an array of char you can also look at std::string