title: Displaying wide chars with printf
body: <p>I'm trying to understand how does printf work with wide characters (<code>wchar_t</code>).</p>
  <p>I've made the following code samples :</p>
  <h1>Sample 1 :</h1>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int     main(void)
  {
      wchar_t     *s;
  
      s = (wchar_t *)malloc(sizeof(wchar_t) * 2);
      s[0] = 42;
      s[1] = 0;
      printf(&quot;%ls\n&quot;, s);
      free(s);
      return (0);
  }
  </code></pre>
  <p><strong>output :</strong></p>
  <pre><code>*
  </code></pre>
  <p>Everything is fine here : my character (<code>*</code>) is correctly  displayed.</p>
  <h1>Sample 2 :</h1>
  <p>I wanted to display an other kind of character. On my system, <code>wchar_t</code> seem encoded  on 4 bytes. So I tried to display the following character :
  <a href="http://unicode-table.com/en/00C9/" rel="noreferrer"><code>É</code></a></p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int     main(void)
  {
      wchar_t     *s;
  
      s = (wchar_t *)malloc(sizeof(wchar_t) * 2);
      s[0] = 0xC389;
      s[1] = 0;
      printf(&quot;%ls\n&quot;, s);
      free(s);
      return (0);
  }
  </code></pre>
  <p>But there is no output this time, I tried with many values from the &quot;encoding&quot; section (cf. previous link) for <code>s[0]</code> (0xC389, 201, 0xC9)... But I never get the <code>É</code> character displayed. I also tried with <code>%S</code> instead of <code>%ls</code>.</p>
  <p>If I try to call printf like this : <code>printf(&quot;&lt;%ls&gt;\n&quot;, s)</code> the only character printed is <code>'&lt;'</code>, the display is truncated.</p>
  <p>Why do I have this problem? How should I do?</p>