 <p>This call </p> <pre><code>scanf_s("%s",msg); </code></pre> <p>is missing the size argument. Change to</p> <pre><code>scanf_s("%s", msg, (unsigned)sizeof msg); </code></pre> <p>You are also doing this</p> <pre><code>for(i=0;msg[i]!=NULL;i++) m[i]=msg[i]; </code></pre> <p>which generates a compiler warning, because <code>NULL</code> is pointer value, not a char value. But its biggest sin is not copying the <code>'\0'</code> string terminator. What do have against <code>strcpy()</code> or even <code>strdup()</code>?</p>