How to update libc::c_char array with String


#1

I have write some FFI code to C/C++,

use libc::c_char;
use std::ffi::CString;

type arr_type = [c_char; 20]; // arr_type is the type in C
let mut arr : arr_type = [0; 20]; 

let s = "happy123";
let c_s = CString::new(s).unwrap();
let s_ptr = c_s.as_ptr();

how can I update the arr with the String s in Rust ? in C/C++ I can use memcpy, strcpy etc…


#2

please don’t double post to stackoverflow and to here.

SO-Link: http://stackoverflow.com/questions/29278089/how-to-update-libcc-char-array-with-string


#3

Why not? Is there a rule against it?