Click to See Complete Forum and Search --> : Array Problem - Please Help!!!
Vlatko
Sep 26th, 2000, 02:14 PM
What is wrong here.I want to set the array myarray depending on the value of the variable e2 and not on some specific number. Why doesn't this work.
int e2 = 15;
char myarray[(int)e2];
parksie
Sep 26th, 2000, 02:18 PM
You can't allocate an array like that. You're allocating it on the stack, so you have to give a constant size. If you want to give it a dynamic size, you have to allocate it on the heap:
int e2 = 15;
char *myarray = new char[e2];
// ...use myarray
delete myarray; // Very important!!!
...although don't try to use myarray after it's been deleted.
Vlatko
Sep 27th, 2000, 10:50 AM
Thanks for the code it works just fine
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.