• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JNI problem

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I guess we dont have any forum particularly for JNI... thats y posting the porblem here...
whats the difference between passing a jstring from a java program to 'c' method AND using scanf from within the 'c' code to read the string from java execution environment... somewhat like done in the following 'c' method.....
here jstring 'str' is passed from a java method AND another string is read from the command prompt using scanf("%s", buf)
why in the first case we require conversion from unicode to UTF8 and not in the second case ....

JNIEXPORT jstring JNICALL Java_HelloName_displayHelloName(JNIEnv *env, jobject obj, jstring str)
{
char buf[128];
const char *s = (*env)->GetStringUTFChars(env, str, 0);
printf("Hello , %s\n",s);
(*env)->ReleaseStringUTFChars(env, str, s);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);

}

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amit shukla:
Hi all,
I guess we dont have any forum particularly for JNI... thats y posting the porblem here...
whats the difference between passing a jstring from a java program to 'c' method AND using scanf from within the 'c' code to read the string from java execution environment... somewhat like done in the following 'c' method.....
here jstring 'str' is passed from a java method AND another string is read from the command prompt using scanf("%s", buf)
why in the first case we require conversion from unicode to UTF8 and not in the second case ....

JNIEXPORT jstring JNICALL Java_HelloName_displayHelloName(JNIEnv *env, jobject obj, jstring str)
{
char buf[128];
const char *s = (*env)->GetStringUTFChars(env, str, 0);
printf("Hello , %s\n",s);
(*env)->ReleaseStringUTFChars(env, str, s);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);

}


Hey
If you know the answer please let me know
thanks
gat
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
gat98,
Please review the JavaRanch naming policy and re-register.
Thanks,
John
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic