how to convert an int array to a char array

A

andrea_

I've got a problem: I must use an int java array in a C code. Using JNI
i wrote this code:

jsize len = (*env)->GetArrayLength(env, payload); //payload is the
name of java array
jint *body = (*env)->GetIntArrayElements(env, payload, 0);
int cpayload [len]; // C array
int i;
for (i=0; i<len; i++)
{
cpayload = body; // copying the java array value into C array
value
}

input.d_ip=0;
input.data_size=len;
input.data=(u_char)*body; //here there is the error

the compiler says this:
warning: assignment makes pointer from integer without a cast

P.S. data is define in this way:
u_char *data;
 
Z

Zara

andrea_ said:
I've got a problem: I must use an int java array in a C code. Using JNI
i wrote this code:

jsize len = (*env)->GetArrayLength(env, payload); //payload is the
name of java array
jint *body = (*env)->GetIntArrayElements(env, payload, 0);
int cpayload [len]; // C array
int i;
for (i=0; i<len; i++)
{
cpayload = body; // copying the java array value into C array
value
}

input.d_ip=0;
input.data_size=len;
input.data=(u_char)*body; //here there is the error

the compiler says this:
warning: assignment makes pointer from integer without a cast

P.S. data is define in this way:
u_char *data;


The cast is wrong; write:

input.data=(u_char *)body;
 
F

Flash Gordon

Zara said:
The cast is wrong; write:

input.data=(u_char *)body;

That will get rid of the warning and, assuming u_char is a typedef for
unsigned char is completely valid as far as C is concerned. However I
would suggest the OP ask somewhere where the JNI is on topic to see if
this is the right was to access a Java int array. Since the J in JNI
stands for Java I would suggest a group with java in the name, possible
comp.lang.java.programmer, but check *their* FAQ, charter and a load of
posts to see what goes on there before posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top