how to convert an int array to a char array

Discussion in 'C Programming' started by andrea_, Sep 7, 2005.

  1. andrea_

    andrea_ Guest

    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;
     
    andrea_, Sep 7, 2005
    #1
    1. Advertising

  2. andrea_

    Zara Guest

    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 = 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;
     
    Zara, Sep 7, 2005
    #2
    1. Advertising

  3. andrea_

    Flash Gordon Guest

    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.
     
    Flash Gordon, Sep 7, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,223
    Martien Verbruggen
    Jun 27, 2003
  2. trey

    newbie: char* int and char *int

    trey, Sep 10, 2003, in forum: C Programming
    Replies:
    7
    Views:
    405
    Irrwahn Grausewitz
    Sep 10, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,650
    Old Wolf
    Jan 20, 2004
  4. lovecreatesbeauty
    Replies:
    1
    Views:
    1,062
    Ian Collins
    May 9, 2006
  5. gert
    Replies:
    20
    Views:
    1,171
Loading...

Share This Page