pointer problem
Hi, I have been having a problem with my pointers lately. I can''t figure out what the heck is going wrong!
I am using an array of pointers pointing to arrays, which is called lparray. I am doing this because in the real program, I need to be able to change the amount of elements in an array. So this is what I have come up with (which obviously doesn''t work). If you run it you will find that lparray points to the same address. What''s the problem?
class TheClass
{
public:
char (*lparray[2])[64];
void ChangeArray(char name1[64], char name2[64]);
};
void TheClass::ChangeArray(char name1[64], char name2[64])
{
strcpy((*lparray[0]), name1);
strcpy((*lparray[1]), name2);
}
void main (void)
{
TheClass Class;
char temparray[64];
int a = 0;
Class.ChangeArray("array1", "array2");
for (a = 0; a < 2; a++)
{
cout << (*Class.lparrayLink
I''d use STL for the resizable array - leaves you to worry about the more important things.
Brad
Brad
brad_beveridge is right, you should use the STL (it''s much easier). But if you really want to use pointers, I suggest you do it like this:
I didn''t quite understand what you wanted to do with that char
Dormeur
|
I didn''t quite understand what you wanted to do with that char
(*lparray[2])[64]
structure, but to me, it seems too complex if you just want to make a variable sized array of strings.Dormeur
Wout "Dormeur" NeirynckThe Delta Quadrant Development Page
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement