1st allocate the space needed for the whole hash's "string" representation:
From C99 on this could be done using a VLA:
char str[2*len + 1] = "";
Or just allocate it dynamically:
char * str = calloc(2*len + 1, sizeof(*str));
Then use sprintf()
to get the single bytes' representions and just concatenate them:
for (size_t i = 0; i < len; ++i)
{
char tmp[3];
/* Use the hh length modifier, together with casting to a character to make sure to
NOT overflow tmp. */
sprintf(tmp, "%02hhx", (unsigned char) result[i]);
strcat(str, tmp);
}
If having used dynamic allocation do not forget the free the memory allocated to s
if not needed anymore:
free(str);