Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to convert an int array to a char array

Reply
Thread Tools

how to convert an int array to a char array

 
 
andrea_
Guest
Posts: n/a
 
      09-07-2005
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[i] = body[i]; // 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;

 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      09-07-2005
andrea_ wrote:
> 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[i] = body[i]; // 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;


 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      09-07-2005
Zara wrote:
> andrea_ wrote:
>
>>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);


<snip>

>> 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;


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.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
int urldecode(char *src, char *last, char *dest) gert C Programming 20 02-16-2007 11:28 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
newbie: char* int and char *int trey C Programming 7 09-10-2003 03:24 AM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57