Read array Harbour from C
Posted: Sat Oct 26, 2019 6:24 pm
Hi,
I am trying to read a harbour array from a function in C, but I have problems trying to read the strings, the function in C is displaying rare characters when the data type is a string. I also need to know and display the string length,
I don't know how to do it either.
This is the code:
Any idea?, I appreciate your help.
Regards,
Javier
I am trying to read a harbour array from a function in C, but I have problems trying to read the strings, the function in C is displaying rare characters when the data type is a string. I also need to know and display the string length,
I don't know how to do it either.
This is the code:
Code: Select all
#pragma -w2
PROCEDURE Main()
LOCAL aValues := { .F., 'string 1', .T., .F., 5689, 6.593, 'text', 126, 0.3,9 }
CLS
TestArray( aValues )
RETURN
#pragma BEGINDUMP
#include "hbapi.h"
HB_FUNC_STATIC( TESTARRAY )
{
#define btoa(x) ((x)?"true":"false")
PHB_ITEM aValues = hb_param( 1, HB_IT_ARRAY );
HB_ULONG size = hb_arrayLen( aValues );
HB_ULONG i;
int *tmpInt;
long *tmpLong;
float *tmpFloat;
char *tmpString;
HB_BOOL *tmpBool;
for( i = 1; i <= size; ++i )
{
switch ( hb_arrayGetType( aValues, i ) )
{
case HB_IT_STRING:
tmpString = ( char* ) malloc( sizeof( char ) );
*tmpString = hb_arrayGetC( aValues, i ); // hb_arrayGetC - Retrieves the string contained on an array element
// hb_arrayGetCPtr - Retrieves the string pointer on an array element
printf( "valor cadena %c\n", *tmpString );
//printf( "valor cadena \n" );
break;
case HB_IT_INTEGER:
tmpInt = ( int* ) malloc( sizeof( int ) );
*tmpInt = hb_arrayGetNI( aValues, i );
printf( "valor entero %d\n", *tmpInt );
free( ( int* ) *tmpInt );
break;
case HB_IT_LONG:
tmpLong = ( long* ) malloc( sizeof( long ) );
*tmpLong = hb_arrayGetNL( aValues, i );
printf( "valor entero largo");
break;
case HB_IT_DOUBLE:
tmpFloat = ( float* ) malloc( sizeof( float ) );
*tmpFloat = ( float ) hb_arrayGetND( aValues, i );
printf( "valor double %f\n", *tmpFloat ); // decimal
break;
case HB_IT_LOGICAL:
tmpBool = ( HB_BOOL* ) malloc( sizeof( HB_BOOL ) );
*tmpBool = hb_arrayGetL( aValues, i );
free( ( HB_BOOL* ) *tmpBool );
//printf("%s\n", btoa( *tmpBool )); // it works
printf("%s\n", *tmpBool ? "verdadero" : "falso");
break;
default: break;
}
}
}
#pragma ENDDUMP
Regards,
Javier