dcsimg
I am trying to use java to pass some command line ...
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Allison_Santoro
Posted On:   Tuesday, November 21, 2000 08:32 AM

I am trying to use java to pass some command line arguments to c++ code. I have successfully passed an array of strings from the java code to the C++ code. I have converted the objectArray to the argv array and I can print it out. I need to be able to use this array in the same function after the I exit the for loop. The problem is after I release the utf characters I get garbage in my array. So I tried to release them after I use them but then then I get an error stating that the parameters that I passed the releaseutf method are undefined. here is the code that I am using /* Declare a char array for argv */ char const* argv[32]; int i; for (i = 0; i < argc ; i++) { /   More>>

I am trying to use java to pass some command line arguments to c++ code. I have successfully passed an array of strings from the java code to the C++ code. I have converted the objectArray to the argv array and I can print it out. I need to be able to use this array in the same function after the I exit the for loop. The problem is after I release the utf characters I get garbage in my array. So I tried to release them after I use them but then then I get an error stating that the parameters that I passed the releaseutf method are undefined. here is the code that I am using


/* Declare a char array for argv */

char const* argv[32];

int i;

for (i = 0; i < argc ; i++)

{

/* obtain the current object from the object array */

jstring myObject = (jstring)env->GetObjectArrayElement(argvj, i);


/* Convert the object just obtained into a String */

const char *str = env->GetStringUTFChars(myObject,0);


/* Build the argv array */

argv[i]=str;


/* print the argv array to the screen */

printf ("argv[%i] = %s
",i,argv[i]);


/* release the characters so as not to create memory leaks */

env->ReleaseStringUTFChars(myObject, str);

}


I also tried using the strcpy function to replace the following line:
argv[i]=str;
replace with
strcpy(argv[i],str);
but I get an error about converting *char to char
I tried never releasing them but that too causes a headache. I need to be able to use this array outside of the for loop and to release the resources. Any ideas?

   <<Less
About | Sitemap | Contact