Program crashes if input is >307

I'm trying to create a program that generates a list of random ascii characters (a-z, A-Z). The list is to be determined by the input of the user. I capped the list at 500 characters, but the program crashes when I tell it to make the list any number greater than 307. Heres what I have:

//removed

I'd like it so the user could input any number up to 500, rather than the program crashing at 308+. Any help would be much appreciated!
Last edited on
I think the problem is here. The way you declare array is suspect. (In fact, Visual Studio isn't even compiling it.)
 
int size, seed, array[size], g=65, lineCount=10;


Why not just declare it like this?
int size, seed, array[500], g=65, lineCount=10;
On second thought, why declare array[size] at all? You never do anything useful with the array.
Actually, you can't define array[size] like that at all. Unless you're creating a dynamic array, when you define the size of an array it must be a constant. In this case, you're using an undefined variable, meaning that it can be any number available. That can cause some serious issues. In this case, you want to use a dynamic array. That way, it will function the way you want it to.
I'm just learning bout arrays and it's a new concept to me. The program has to follow these guidelines:

removed



Since the array size is dependent on the user's input, I thought array[size] would be needed.

I fixed the way i declared array to array[500] and I'm no longer experiencing the crash if its over 307 characters, but, while it's working, I'd like to know if the way I'm going about this is unorthodox. Thanks again for the help!
Last edited on
Topic archived. No new replies allowed.