title: null terminating a string
body: <p>gcc 4.4.4 c89</p>
  
  <p>What is the standard way to null terminate a string? When I use the <code>NULL</code> I get a warning message.</p>
  
  <pre><code>*dest++ = 0; 
  *dest++ = '\0'; 
  *dest++ = NULL; /* Warning: Assignment takes integer from pointer without a cast */
  </code></pre>
  
  <p>Source code:</p>
  
  <pre><code>size_t s_strscpy(char *dest, const char *src, const size_t len)
  {
      /* Copy the contents from src to dest */
      size_t i = 0;
      for(i = 0; i &lt; len; i++)
      *dest++ = *src++;
  
      /* Null terminate dest */
       *dest++ = 0; 
  
      return i;
  }
  </code></pre>
  
  <p>Another question: I deliberately commented out the line that null terminates. However, it still correctly printed out the contents of the dest. The caller of this function would send the length of the string by either included the <code>NULL</code> or not. i.e. <code>strlen(src) + 1</code> or <code>stlen(src)</code>.</p>
  
  <pre><code>size_t s_strscpy(char *dest, const char *src, const size_t len)
  {
      /* Copy the contents from src to dest */
      size_t i = 0;
      /* Don't copy the null terminator */
      for(i = 0; i &lt; len - 1; i++)
      *dest++ = *src++;
  
      /* Don't add the Null terminator */
      /* *dest++ = 0; */
  
      return i;
  }
  </code></pre>