title: How to print string first n bytes when the string's length is greater than n?
body: <p>So I have a string that has a certain amount of bytes (or length). I say bytes because there is no NULL terminator at the end of the string. Though, I know how long the string is. Normally, as we all know, when you <code>printf("%s", str);</code>, it will keep printing every byte until it gets to a NULL character. I know there is no C string that is not NULL terminated, but I have a weird situation where I'm storing stuff (Not specifically strings) and I don't store the NULL, but the length of the "thing".</p>
  
  <p>Here is a little sample:</p>
  
  <pre><code>char* str = "Hello_World"; //Let's use our imagination and pretend this doesn't have a NULL terminator after the 'd' in World
  long len = 5;
  
  //Print the first 'len' bytes (or char's) of 'str'
  </code></pre>
  
  <p>I know you are allowed to do something like this:</p>
  
  <pre><code>printf("%.5s", str);
  </code></pre>
  
  <p>But with that situation, I'm hard coding the 5 in, though with my situation, the 5 is in a variable. I would do something like this:</p>
  
  <pre><code>printf("%.(%l)s", len, str);
  </code></pre>
  
  <p>But I know you can't do that. But gives you an idea of what I'm trying to accomplish.</p>