title: How to use the strncpy_s function from visual c++?
body: <p>I am learning some new things in C++, and I was trying to test this strncpy_s function from Visual C++. However I am running into some problems as program crashes and I dunno whats going on but I am sure it is a pretty stupid problem. The source code is something like this:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include &lt;cstring&gt;
  
  int main()
  {
      char *p;
      p=(char *)malloc(sizeof(char)*strlen("Hello!\n"));
      strncpy_s(p,strlen("Hello!\n"),"Hello!\n",strlen("Hello!\n"));
      std::cout &lt;&lt; p;
      std::cout &lt;&lt; strlen("Hello!\n") &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>As I said I am not using std::string coz I want to try this new function and know how it works.</p>