This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
cni converting String args[]
- From: littlejohn at paranoici dot org
- To: java at gcc dot gnu dot org
- Date: Fri, 10 Dec 2004 17:20:19 +0100
- Subject: cni converting String args[]
Hi,
I'm quite lost finding a proper way to convert String[] args to a
char** array. The code I did is:
jint A::init(JArray< ::java::lang::String *> *args) {
int argc = 0;
char* arguments[argc];
if (args != NULL)
{
argc = args->length;
arguments[argc];
/*
* convert the JArray<String*>* in char**
*/
::java::lang::String** argsElements = elements(args);
//args[0];
for (int i = 0; i < argc; i++) {
//arguments[i] = (char *) JvGetStringChars(argsElements[i]);
arguments[i] = (char *) elements(argsElements[i]->getBytes());
//arguments[i] = (char *) elements(argsElements[i]->toCharArray());
printf("%s\n ", arguments[i]);
}
}
return 0;
}
Aside this method does nothing but the conversion, I think I'm
misusing the elements function. On the first iteration the printf code
goes ok, on the second it writes garbage of gets a SIGSEGV, because
the argsElements[1] points to argsElement[0]+4 (I checked with gdb).
The commented out lines do not work either.
What am I missing?
Cheers,
lj