We have a vendor supplied api which has a struct defined as
typedef struct
{
char duo_word[8];
} duo_word;
They send us data in this structure which we then have to pass to our java app through jni.
printf("Number: : %i\n", duo_word_inst);
prints the correct int value e.g 52932, but
printf("Number: : %s\n", duo_word_inst);
prints nothing. More over if I use jni code below my java process receives gibberish.
jstring jstrBuf = (*env)->NewStringUTF(env, (char*)(duo_word_inst));
(*env)->SetObjectField(env, *ret_obj, fld_id, jstrBuf);
sends gibberish to java e.g ÄÎ
// I have got some example data captured from VS debugger below.
duo_word duo_word_inst = { .duo_word = { 'º', '\b', '\x1', '\0', 'À', '\xe', '2', 'a' } };
printf(" %i ", duo_word_inst); // gives 67770 which is correct.
My C skills are very elementary so I would really appreciate if some one could point out the silliness I am doing here. Thanks,