Page 1 of 1

Returning an array from C code

Posted: Thu Jul 09, 2009 11:26 am
by xProgrammer
Hi all

I need to return an array (or perhaps write to an (x)Harbour array) from a C function where I have something like

char **things

I need to iterate through things like this (given that there are int num_things of things:

for ( loop_counter = 0; loop_counter < num_things; loop_counter++ )
{
// do something here to put things[loop_counter] into the array
}
for ( loop_counter = 0; loop_counter < num_things; loop_counter++ )
{
free( things[loop_counter] );
}
free( things );

// if above is building an array I would need to pass it back here
// but if above wrote to an existing (x)harbour array then there would be no work to be done here.

Can someone help please?

Thanks

Re: Returning an array from C code

Posted: Thu Jul 09, 2009 4:15 pm
by Antonio Linares
Doug,

Harbour function Directory() is a great example to create and fill mutidimensional arrays from C:

http://harbour-project.svn.sourceforge. ... hrev=11679

Re: Returning an array from C code

Posted: Thu Jul 09, 2009 8:24 pm
by xProgrammer
Thanks Antonio

Code is most instructive. Should be put to good use shortly. First target will be native CUPS support. If done as a class it would presumably be TCUPS (teacups)?

Regards

Doug