|
-
Sep 26th, 2000, 02:14 PM
#1
Thread Starter
Frenzied Member
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.
Code:
int e2 = 15;
char myarray[(int)e2];
-
Sep 26th, 2000, 02:18 PM
#2
Monday Morning Lunatic
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:
Code:
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 27th, 2000, 10:50 AM
#3
Thread Starter
Frenzied Member
Thanks for the code it works just fine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|