title: convert a number in a string to float in c: atof(), strtof() do not work
body: <p>My C is rusty. I am trying to convert a string to float (or double). I have tried atof() and strtof(), and tried following instructions <a href="https://stackoverflow.com/questions/7951019/convert-string-to-float">here</a> and <a href="https://stackoverflow.com/questions/25756939/gnu-c-atof-strtof-and-strtod-fail-debian-for-beagleboard">here</a>. No luck.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char *argv[]) {
    float x;
    char a[20];
    strcpy(a,argv[1]);
    x = strtof(a);
    printf("%s\n",a);
    printf("%f\n",x);
    return 0;
  }
  </code></pre>
  
  <p>No luck. Here's output, on the command line:</p>
  
  <pre><code>prompt$ ./a.out 2.34
  2.34
  1426063.000000
  prompt$
  </code></pre>
  
  <p>If I use atoi() instead, I get 0.0. </p>
  
  <p>Clearly there is something simple I'm missing. This is with gcc 4.8.4 on ubuntu fwiw.</p>
  
  <p>Makes no difference if I compile with -static flag, or use double instead of float (and %e instead of %f), or include math.h. The output changes in some of those cases, but it's still nonsense.</p>
  
  <p>Thanks,
  Peter</p>