title: C++ Windows decimal to UTF-8 Character Conversion
body: <p>I've been using the function below to convert from the decimal representation of unicode characters to the UTF8 character itself in C++. The function I have at the moment works well on Linux / Unix system but it keeps returning the wrong characters on Windows.</p>
  
  <pre><code>void GetUnicodeChar(unsigned int code, char chars[5]) {
      if (code &lt;= 0x7F) {
          chars[0] = (code &amp; 0x7F); chars[1] = '\0';
      } else if (code &lt;= 0x7FF) {
          // one continuation byte
          chars[1] = 0x80 | (code &amp; 0x3F); code = (code &gt;&gt; 6);
          chars[0] = 0xC0 | (code &amp; 0x1F); chars[2] = '\0';
      } else if (code &lt;= 0xFFFF) {
          // two continuation bytes
          chars[2] = 0x80 | (code &amp; 0x3F); code = (code &gt;&gt; 6);
          chars[1] = 0x80 | (code &amp; 0x3F); code = (code &gt;&gt; 6);
          chars[0] = 0xE0 | (code &amp; 0xF); chars[3] = '\0';
      } else if (code &lt;= 0x10FFFF) {
          // three continuation bytes
          chars[3] = 0x80 | (code &amp; 0x3F); code = (code &gt;&gt; 6);
          chars[2] = 0x80 | (code &amp; 0x3F); code = (code &gt;&gt; 6);
          chars[1] = 0x80 | (code &amp; 0x3F); code = (code &gt;&gt; 6);
          chars[0] = 0xF0 | (code &amp; 0x7); chars[4] = '\0';
      } else {
          // unicode replacement character
          chars[2] = 0xEF; chars[1] = 0xBF; chars[0] = 0xBD;
          chars[3] = '\0';
      }
  }
  </code></pre>
  
  <p>Can anyone provide an alternative function or a fix for the current function I'm using that will work on Windows?</p>
  
  <p>--UPDATE--</p>
  
  <pre><code>INPUT: 225
  OUTPUT ON OSX: á
  OUTPUT ON WINDOWS: ├í
  </code></pre>