title: Libtidy HTML to XHTML and save in string C
body: <p>I have this function to convert html in put to xhtml:</p>
  
  <pre><code>char* cleanhtml(char* localhtml)
  {
  char *buffer_;
  static char *cleansed_buffer;
  
  
  // uses Libtidy to convert the buffer to XML
  TidyBuffer output = {0};
  TidyBuffer errbuf = {0};
  int rc = -1;
  bool ok;
  
  TidyDoc tdoc;
  tdoc = tidyCreate();                     // Initialize "document"
  
  ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
      rc = tidySetErrorBuffer( tdoc, &amp;errbuf );      // Capture diagnostics
      rc = tidyParseString(tdoc, localhtml);           // Parse the input
      rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
      rc = tidyRunDiagnostics( tdoc );               // Kvetch// If error, force output.
      rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
      rc = tidySaveBuffer( tdoc, &amp;output );          // Pretty Print
      cleansed_buffer = (char*) malloc(output.size + 1);
      memcpy (cleansed_buffer, (char*)output.bp,output.size);
      tidyBufFree( &amp;output );
      tidyBufFree( &amp;errbuf );
      tidyRelease( tdoc );
      return cleansed_buffer;
  }
  </code></pre>
  
  <p>But the problem is it is not working correctly...for some reason the xhtml being given out is not being able to be parsed and it is wrong format. So how can libtidy be used to convert a given string(huge string) to xhtml in right format.</p>
  
  <p>And can somebody please give me link to the latest libtidy (dlls,includes) for C.I can't find it anywhere...not even on there website..</p>