fork download
  1. #include <string.h>
  2. #include <malloc.h>
  3.  
  4. char* HexEncode(char* txt)
  5. {
  6. char* hexTxt = calloc(2*strlen(txt)+1,1);
  7. for(char* p=hexTxt; *txt; p+=2)
  8. {
  9. sprintf(p, "%02x", *txt++);
  10. }
  11. return hexTxt;
  12. }
  13.  
  14. int main() {
  15. char* hexText = HexEncode("Hello\t\n\rWorld");
  16.  
  17. printf("Hexed is %s\n", hexText);
  18.  
  19. free(hexText);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 2300KB
stdin
Standard input is empty
stdout
Hexed is 48656c6c6f090a0d576f726c64