I have the following code written in 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;
}
As far as I understand, the function above returns a pointer to a character (and not to an array of characters). Am I correct?
IF that is the case, how can I turn the function result (i.e. a pointer to a character) into an array of characters so that I can read them one by one?
mallocseems larger than1. You can probably effectively reach an array of characters through that pointer.