title: String format works in fprintf but doesn't work in sprintf, gives segmentation fault
body: <pre><code>fprintf(fp,"IP: %d:  %.*s\n",
          ip, 
          strstr(strstr(p-&gt;data, "User-Agent:"),"\n") - strstr(p-&gt;data, "User-Agent:"),
          strstr(p-&gt;data, "User-Agent: ") );
      fclose(fp);
  </code></pre>
  
  <p>Hi All, as you can see, in the above statement, I am trying to write off just the User Agent header from a char pointer which contains the entire http packet data. The thing is, After fiddling with the string format, I came up with this %.*s format which lets me, dynamically select the number of characters to be printed to the file, and then prints them. What the code is basically doing is, first, it's printing an int, then the number of chars from the occurrence of "User-Agent:" to the very next occurrence new line character is passed, and that amount of chars are then passes starting at where the "User-Agent:" starts, from the entire packet data string. I know it's all pretty messy, but it's working fine. Except that it's not working in sprintf.</p>
  
  <p>Please save all my hard word! Any help is appreciated!</p>
  
  <pre><code>    char *stat;
      sprintf(stat,"%.*s\0",
          strstr(strstr(p-&gt;data, "User-Agent:"),"\n") - strstr(p-&gt;data, "User-Agent:"),
          strstr(p-&gt;data, "User-Agent: ")) ;
  </code></pre>