 <p>Try defining <code>a</code> like this:</p> <pre><code>char a[10]; </code></pre> <p>Currently you are passing an uninitialized pointer to snprintf, so you get undefined behavior when snprintf writes to it.</p>