c与python之间传递特殊字符

各位大侠。我现在有以下使用情况,从C语言传递abc\0xyz给python,从python传递给C语言侧xyz\0abc。就是在c和python之间传递中间有\0的连续字符。如果按字符串传递,会被截断。如何才能保留不被截断呢?谢谢!

慕哥6287543
浏览 843回答 1
1回答

当年话下

>>> from ctypes import *>>> libc=cdll.msvcrt>>> libc.printf("hello %s\n","world")hello world12>>>>>> p = create_string_buffer("Hello", 30)>>> n=libc.sprintf(p,"hello %s\n","world")>>> n12>>> print p<ctypes.c_char_Array_30 object at 0x02247C10>>>> dir(p)['__class__', '__ctypes_from_outparam__', '__delattr__', '__delitem__', '__delslice__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__','__getslice__', '__hash__', '__init__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__setslice__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__','_b_base_', '_b_needsfree_', '_length_', '_objects', '_type_', 'raw', 'value']>>> p.value'hello world\n'>>>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python