title: sprintf not functioning correctly when concatenating an int and string
body: <p>I have the following code (in a server [sender] program):</p>
  
  <pre><code>#define PAYLOAD 256
  
  //...some more code...
  
      int l;
      char packet[PAYLOAD];
      char seqNumNpacket[sizeof(l) + sizeof(packet) + 1]; //to account for the number, space and the packet
  
      FILE *fp2;
      fp2 = fopen(req, "r");
      l = 0;        
      char seqNumNpacket[sizeof(l) + sizeof(packet) + 1];
      //... some more code...
      n = fread(packet, 1, PAYLOAD, fp2);
      packet[n] = '\0';
      printf("%s", packet);
      sprintf(seqNumNpacket, "%d %s", l, packet);
      printf("%d %s", seqNumNpacket); //A
  </code></pre>
  
  <p>Here I am trying to read bytes from a file, and then put it together in a string with a number so that I can send it over to other process using <code>sendto()</code>/<code>recvfrom</code>.</p>
  
  <p>The problem arises when I use <code>sprintf</code> to stick them together. Somehow instead of writing a string of the fashion of "<code>seqNum</code> <code></code> <code>packet</code>" it ends up as "<code>seqNum</code> <code></code> <code>packet</code> <code>seqNUm</code>".</p>
  
  <p>I have no clue what is causing this and thus haven't found a way to solve it. Thanks for the help beforehand with this <em>silly</em> question.</p>