#include <string.h>
#include <malloc.h>

char* HexEncode(char* txt)
{
	char* hexTxt = calloc(2*strlen(txt)+1,1);
	for(char* p=hexTxt; *txt; p+=2)
	{
		sprintf(p, "%02x", *txt++);
	}
	return hexTxt;
}

int main() {
	char* hexText = HexEncode("Hello\t\n\rWorld");
	
	printf("Hexed is %s\n", hexText);
	
	free(hexText);
	
	return 0;
}