I need to convert a string into a float. If the string is not a number I wish to return 0.
I have tried to test if the atof()
function would work for this by using the following code:
printf("%f", atof("1a"));
From my understanding of atof, the value returned when atof cannot convert is 0, and yet this line prints 1.0
.
Why does this happen? By the documentation I understood that atof is meant to return 0 whenever the input is not a number.