Removing whitespaces in a string
char* result = strcpy((char*)malloc(str.length()+1), str.c_str());



This seems more suited for a C program than a C++ one. In fact, with C++11, you don't need to write your own function. 

Behold: std::remove_if

Note:


  std::remove_if
  
  Removes all elements satisfying specific criteria from the range
  [first, last) and returns a past-the-end iterator for the new end of
  the range.
  
  A call to remove is typically followed by a call to a container's
  erase method, which erases the unspecified values and reduces the
  physical size of the container to match its new logical size.


This is what you would do:

str.erase(remove_if(str.begin(), str.end(), ::isspace), str.end());


I am not sure if this is the safest or most efficient method, but I think it's definitely an improvement to what you have done.