triumphost 120 Posting Whiz

I'm trying to convert this (Pascal) to C++.. My attempt is below this..

function CompressString(const Str: string): string;
var
  Destlen:longword;
begin
  result := '';
  Destlen :=BufferLen;
  if length(str) < 1 then
    exit;
  if compress(BufferString,destlen,PChar(Str),length(str)) = Z_OK then
  begin
    setlength(result,Destlen + SizeOf(Integer));
    PInteger(@result[1])^ := Length(str);
    Move(bufferstring[0],result[5],Destlen);
  end;
end;
string CompressString(string Source)
{
    unsigned long dsize;                    //Compressed Datasize
    size_t SourceSize = Source.size();
    size_t BufferLen = SourceSize + (SourceSize * 0.1) + 12;        //Must have a min buffer size = to the source + itself * 0.1 + 12
    char dest[BufferLen];

    if (SourceSize < 1)
        return dest;

    //Compress everything from source to destination
    if (compress((unsigned char *)dest, &dsize, (const unsigned char *)Source.c_str(), SourceSize) != Z_OK)
        cout<<"Compression Error!\n";

    return dest;
}

But they both print different results.. any idea why?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.