title: C convert section of char array to double
body: <p>I want to convert a section of a char array to a double. For example I have:</p>
  
  <pre><code>char in_string[] = "4014.84954";
  </code></pre>
  
  <p>Say I want to convert the first <code>40</code> to a double with value <code>40.0</code>. My code so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt; 
  
  int main(int arg) {
    char in_string[] = "4014.84954";
    int i = 0;
    for(i = 0; i &lt;= sizeof(in_string); i++) {
      printf("%c\n", in_string[i]);
      printf("%f\n", atof(&amp;in_string[i]));
    }
  }
  </code></pre>
  
  <p>In each loop <code>atof</code> it converts the char array from the starting pointer I supply all the way to the end of the array. The output is:</p>
  
  <pre><code>4
  4014.849540
  0
  14.849540
  1
  14.849540
  4
  4.849540
  .
  0.849540
  8
  84954.000000   etc...
  </code></pre>
  
  <p>How can I convert just a portion of a char array to a double? This must by modular because my real input_string is much more complicated, but I will ensure that the char is a number 0-9.</p>