cni converting String args[]
littlejohn@paranoici.org
littlejohn@paranoici.org
Fri Dec 10 16:21:00 GMT 2004
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
More information about the Java
mailing list