How would I resize an array at runtime? I'm using VC++6.0
How would I resize an array at runtime? I'm using VC++6.0
If you declare your array something like this:
char myarray[100];
then the answer is you can't resize it.
To do dynamic resizing, you need a dynamically created array. Lookup the new keyword.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
My preferred method:
long *array = (long*) malloc(width * height * sizeof(long));
then to access, use like a one dimensional array
array[(y * width) + x] = 4;
When done (MUST do this at end of app):
free(array);
There are other ways like using the New operator but I prefer to use malloc, for some reason.
malloc is in stdlib.h
- Tigs
>>To do dynamic resizing, you need a dynamically created array. Lookup the new keyword.
Or look up STL Vectors.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie