title: base64 decode for ISO-8859-1
body: <p>I have the following string.
  "this is a test string (à) with (ä) some western europe chars (ß)"</p>
  
  <p>Using <a href="http://www.motobit.com/util/base64-decoder-encoder.asp" rel="nofollow">http://www.motobit.com/util/base64-decoder-encoder.asp</a>
  I get the following base64 encoded string.</p>
  
  <p>dGhpcyBpcyBhIHRlc3Qgc3RyaW5nICjgKSB3aXRoICjkKSBzb21lIHdlc3Rlcm4gZXVyb3BlIGNoYXJzICjfKQ==</p>
  
  <p>When I try decode this with a C function, I get the following:</p>
  
  <p>./test
  Input string is : dGhpcyBpcyBhIHRlc3Qgc3RyaW5nICjgKSB3aXRoICjkKSBzb21lIHdlc3Rlcm4gZXVyb3BlIGNoYXJzICjfKQ==
  Output string is : this is a test string (�) with (�) some western europe chars (�)</p>
  
  <pre><code>int main()
  {
    char *in = "dGhpcyBpcyBhIHRlc3Qgc3RyaW5nICjgKSB3aXRoICjkKSBzb21lIHdlc3Rlcm4gZXVyb3BlIGNoYXJzICjfKQ==";               
    char out[100]="";
    printf("Input string is : %s\n",in);
    base64_decode(in, out);
    printf("Output string is : %s\n",out);
  
    return 0;
  }
  </code></pre>
  
  <p>It cannot display the upper characters of the iso-8859-1 charset.</p>
  
  <p>I tried the same string with the code from 
  <a href="http://base64.sourceforge.net/b64.c" rel="nofollow">http://base64.sourceforge.net/b64.c</a>
  ./b64 -d infile outfile</p>
  
  <p>infile contains:
  dGhpcyBpcyBhIHRlc3Qgc3RyaW5nICjgKSB3aXRoICjkKSBzb21lIHdlc3Rlcm4gZXVyb3BlIGNoYXJzICjfKQ==</p>
  
  <p>The outfile produced gives back the expected string. 
  When I open it (in emacs or vi), I can see:</p>
  
  <blockquote>
    <p>"this is a test string (à) with (ä) some western europe chars (ß)"</p>
  </blockquote>
  
  <p>But when I cat the file, it shows:</p>
  
  <pre><code>cat outfile 
  this is a test string (�) with (�) some western europe chars (�)
  </code></pre>
  
  <p>locale settings are all UTF8 but anyone know why there is a difference between print/display on standard out and viewing in file?</p>
  
  <p>I was going to start debugging the base64_decode() function but the display may be a red herring. </p>
  
  <p>Any thoughts appreciated. </p>
  
  <p>thanks. </p>