我有以下用 C 编写的代码:
unsigned char * pan_protocol_get_image(unsigned long *psize)
{
long fsize;
unsigned char *result;
(void)pan_socket_write_ulong(MSG_GET_IMAGE);
pan_protocol_expect(MSG_IMAGE);
/* Read the size of the data in the message */
(void)pan_read_long(&fsize);
if (psize) *psize = fsize;
/*
* Allocate a buffer large enough for the result. We add one
* in case the size is zero because we need a valid pointer.
*/
result = (unsigned char *)malloc(fsize + 1);
/* Read the data directly into the result buffer */
(void)pan_read((void *)result, fsize);
return result;
}
据我了解,上面的函数返回一个指向字符(而不是字符数组)的指针。我对么?
如果是这种情况,如何将函数结果(即指向字符的指针)转换为字符数组,以便我可以一个一个地读取它们?