Re: double pointer problem..
There appears to be more than one problem with that source.
1) although you declare
char *p[10];
you then use
p = new char[10]; // in your contest you are creating
// 10, 10 char arrays and assigning
// each array the same address effectively
// overwriting the previous on
I think what you actually meant to say was
p[i] = (char *)new char[10];
2. you use
p[0] = "This";
and you actually intend
strcpy(p[0],"This");
3. In your delete loop you are actually delete pp 10 times?
You allocate it once, and should only delete it once. So this loop
should look something like
for (int i = 0; i < 10 ; i++)
{
delete [] p[i];
}
delete [] pp;
Look at this source and see if isn't closer to way you intend
#include <string.h>
#include <iostream.h>
char *samples[] =
{
{ "This" },
{ "is" },
{ "a" },
{ "test" }
};
void main()
{
char **pp = new char * [4];
for(int i=0; i<4; i++)
{
pp[i] = (char*)new char[10];
strcpy(pp[i],samples[i]);
}
for(i=0; i<4; i++)
delete [] pp[i] ;
delete [] pp;
}
Re: double pointer problem..
Hey, i'm not used to all this pointer stuff, even though i use them alot,...
Whats the delete []pp;
mean???
Word,
Ryan "Radman" Du Bois
Re: double pointer problem..
It should be a good idea to use j for counters instead of i as i between brackets is the tag for putting text in italic.
Re: double pointer problem..