简体   繁体   中英

How to convert ascii to char in NDK?

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

You need to provide NewStringUTF() a c-string (ie 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM