473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to convert an int array to a char array

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;

Nov 15 '05 #1
2 3643
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;
Nov 15 '05 #2
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.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
27
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
13
by: Bryan Parkoff | last post by:
I have two variables: "char A" and "short B". I can be able to convert from A to B using explicit case conversion with no problem like "B = short (A);". Right now, I have two variables: "char T"...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
5
by: Koolrans | last post by:
Hi All, Don't know if this is covered somewhere else. Could not find it. I have a problem for which I need a solution. I have an array of char chr. I want to convert this to an array of...
8
by: Frank Liebelt | last post by:
Hi I try to convert a int array into a char array. My code: void exec() { char mds; int i; int mdc =...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.