python - Casting a c_char_p to a c_char array -


i need access contents of char* casting array

here's demo:

from ctypes import * foo = (c_char * 4)() foo.value = "foo" print foo.raw # => 'foo\x00' foo_ptr = cast(foo, c_char_p) print foo_ptr.value # => 'foo' 

now want convert foo_ptr (c_char * 4). neither of these work

foo_ = (c_char * 4)(foo_ptr) foo_ = cast(foo_ptr, c_char * 4) 

found it

foo_ = (c_char * 4).from_address(foo_ptr._get_buffer_value()) print foo_.raw # => 'foo\x00' 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -