This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]