#include // malloc #include // sprintf char * atohex(unsigned char * a, size_t len, unsigned int * aalen){ char *aa; //two bytes of output per byte of input, plus newline (*aalen) = 2 * len * sizeof *aa + 1; aa = (char*)malloc((*aalen)); for(int i = 0; i < len; i++){ sprintf(aa + (2 * i), "%02x", a[i]); } aa[(*aalen)-1] = '\n'; return aa; }