md5 return toHexString
    AndyC via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Fri Apr 24 10:50:02 PDT 2015
    
    
  
Hi All, I cannot seem to understand whats wrong with this:
// main.d
import std.stdio;
import std.digest.md;
import std.file;
string md5sum(const string fname)
{
     MD5 hash;
     File f = File(fname, "rb");
     foreach( ubyte[] buf; f.byChunk(4096))
     {
         hash.put(buf);
     }
     string s = toHexString!(LetterCase.lower)(hash.finish());
     writeln(s);   //This is correct
     return s;
}
void main()
{
     string crc = md5sum("main.d");
     writeln(crc);  //This is garbage
}
The writeln in md5sum prints correctly, but the "return s" seems 
to mess it up?  What's going on?
Thanks for you time,
-Andy
    
    
More information about the Digitalmars-d-learn
mailing list