Originally posted by: bleeb
If I remember correctly, it dynamically creates an array based on the size of whatever arguments you supply to main. Therefore, I'm not sure you can input an array size.
Heh, great explanation for someone calling a beginner a moron.
First off, argv is an array of strings (more specifically, C strings, or char arrays). If argv[1] is the argument with your array size, then it first has to converted from a string to an int (use the library function
sprintf).
Secondly in C/C++, arrays on the stack cannot be sized at runtime. Their size has to be known at compile time.
But an array on the heap can be sized at runtime. Like any other data on the heap, you'd access such an array through a pointer variable. Initialize the array with the new operator. For example:
int *someArray;
someArray = new int[variableSizeFromArgv];
Remember to properly delete the array later:
delete [] someArray;
I know I didn't give you exact source code from A to Z, but this is plenty of info to get you on the right track. Google is a great search engine and will often help you find answers to specific programming questions.