c++ - Obj-C NSLog a buffer -


i have got following function trying print datain out nslog,

some_function (const void *datain, size_t datainlength) {     nsmutablestring *in1 = [nsmutablestring string];     (int i=0; i<datainlength; i++)         [in1 appendformat:@"%02x", datain[i]]; } 

this current code, upon compilation "error: subscript of pointer incomplete type 'const void'"

anyone know how can fix this?

you'll need couple of casts:

void some_function (const void *datain, size_t datainlength) {     const char *cdata = (const char *)datain;     nsmutablestring *in1 = [nsmutablestring string];     (int i=0; i<datainlength; i++)         [in1 appendformat:@"%02x", (unsigned)cdata[i]]; } 

the first [i] knows how many bytes offset buffer (sizeof(char) known) , secondly casting unsigned that's printf-formatting expects size of %x specifier values (you don't need one, i'm fussy).


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -