Why does the atof() function not return 0 when I pass it a string with invalid characters after a number?
<p>I need to convert a string into a float. If the string is not a number I wish to return 0.</p>

<p>I have tried to test if the <code>atof()</code> function would work for this by using the following code:</p>

<pre><code>printf("%f", atof("1a"));
</code></pre>

<p>From my understanding of atof, the value returned when atof cannot convert is 0, and yet this line prints <code>1.0</code>.</p>

<p>Why does this happen? By the documentation I understood that atof is meant to return 0 whenever the input is not a number.</p>