From: | Jack York |
Date: | 17 Aug 2000 at 04:21:06 |
Subject: | Re: Passing a ptr |
Hello Robert
On 14-Aug-00, Robert Templeton wrote:
>>> Ok, I tried the following but it doesn't work. I am assuming I am
>>> not addressing the variables in the correct way within the
> funtion.
>>> Here's what I am doing:
>>
>> Well, you mentioned in the next mail that you stopped trying to do
> it this
>> way, but I'd still like to warn you about something:
>>
>>> if (*array = (mystruct **) AllocVec ( arraysize * sizeof
> (mystruct)))
>>
>> Shouldn't you be using 'sizeof(mystruct *)' as you are actually
> allocating
>> an array of pointers to mystruct and not an array of mystructs if I
> am not
>> mistaking.
> Get a good book on algorithms in C (covering arrays, lists, heaps,
> sorts, stacks, and such). This kind of aggrevation can be avoided
> completely because the template routines are laid out for you with no
> need for trial and error.
Thanks for the suggestion Robert. Actually I have used this method
many times so generating the array is not the problem (not
withstanding my poor job of checking the code for typing errors. :) )
But whenever I used it before it was always within the same function
so I never had a problem. I have also passed pointers to pointers before
and understand how to reference them (or so I thought) but when I
do it that way here, it still fails. That is why I was, and still am,
asking the question.
So, if anyone still feels like being bothered, I sure could use
an explantion as to why this doesn't work (I hope it's not another
typo). If I put printf( "%d\n", i) in the for loop, it counts to 4
before it dies even though arraysize = 10.
BOOL MakeArray (mystruct ***array, LONG arraysize)
{
if (**array = (mystruct ***) AllocVec ( arraysize * sizeof (mystruct
*)))
{
for (i = 0; i < arraysize; i++)
{
if ( ! *((array[i]) = (mystruct *) AllocVec (sizeof (mystruct)))
break;
Jack
Jack