title: Print first N characters of a string (C)
body: <p>My objective is to print out the first N characters (the <strong>len</strong> variable) of a string using a simple for loop. However, the code doesn't seem to work. e.g. with the input <code>printFrstChars(&quot;Example&quot;,3)</code> the code should print out <code>Exa</code>, but it does not print out <strong>anything</strong>.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  void printFrstChars (char inp[], int len)
  {
      for(int i = 0; inp[i] != '\0' &amp;&amp; i &lt;= len; i++){
          printf(&quot;%s&quot;, inp[i]);
  
      }
  
  }
  
  int main ()
  {   
      int len = 0;
      char inp[100];
      printf(&quot;Input string and length:\n&quot;);
      scanf(&quot;%99s %d&quot;, &amp;inp, &amp;len);
      printFrstChars(inp, len);
     
  
      return 0;
  }
  </code></pre>
  <p>I went over the code multiple times and I (obviously) did not find the mistake that causes this. I would guess that it is either a mistake subtle enough to hide from my beginner eye, or the whole approach is wrong.</p>