How to convert ascii to char in NDK?

0

I am trying to use convert ASCII to Char in Android NDK but it gives me Fatal error for segement and my app force stops. Code:

value = "116";
char word = atoi(value);
return (*env)->NewStringUTF(env, word);

Error:

 Fatal signal 11 (SIGSEGV) at 0x00000074
android
c
android-ndk
java-native-interface
asked on Stack Overflow Mar 28, 2015 by Wahib

1 Answer

2

You need to provide NewStringUTF() a c-string (i.e. an array of char with an ending null):

value = "116";
char word[2];
word[0] = atoi(value);  // first char converted as you want
word[1] = 0;            // null termination (aka '\0')              
return (*env)->NewStringUTF(env, word);
answered on Stack Overflow Mar 28, 2015 by Christophe • edited Mar 28, 2015 by Christophe

User contributions licensed under CC BY-SA 3.0