How would I resize an array at runtime? I'm using VC++6.0
Printable View
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.
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
>>To do dynamic resizing, you need a dynamically created array. Lookup the new keyword.
Or look up STL Vectors.