title: Printf a buffer of char with length in C
body: <p>I have a buffer which I receive through a serial port. When I receive a certain character, I know a full line has arrived, and I want to print it with <code>printf</code> method. But each line has a different length value, and when I just go with:</p>
  
  <pre><code>printf("%s", buffer);
  </code></pre>
  
  <p>I'm printing the line plus additional chars belonging to the former line (if it was longer than the current one).</p>
  
  <p>I read <a href="http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/" rel="noreferrer">here</a> that it is possible, at least in C++, to tell how much chars you want to read given a <code>%s</code>, but it has no examples and I don't know how to do it in C. Any help?</p>
  
  <p>I think I have three solutions: </p>
  
  <ul>
  <li>printing char by char with a <code>for</code> loop</li>
  <li>using the termination character</li>
  <li>or using .* </li>
  </ul>
  
  <p>QUESTION IS: Which one is faster? Because I'm working on a microchip PIC and I want it to happen as fast as possible</p>