title: atol(), atof(), atoi() function behaviours, is there a stable way to convert from/to string/integer?
body: <p>In these days I'm playing with the C functions of <strong>atol(), atof() and atoi()</strong>, from a blog post I find a tutorial and applied:</p>
  
  <p>Here are my results:</p>
  
  <pre><code>void main()
  {
      char a[10],b[10];
      puts("Enter the value of a");
      gets(a);
      puts("Enter the value of b");
      gets(b);
      printf("%s+%s=%ld and %s-%s=%ld",a,b,(atol(a)+atol(b)),a,b,(atol(a)-atol(b)));
      getch();
  }
  </code></pre>
  
  <p>There is <code>atof()</code> which returns the float value of the string and <code>atoi()</code> which returns integer value.</p>
  
  <p>Now to see the difference between the 3 I checked this code:</p>
  
  <pre><code>main()
  {
      char a[]={"2545.965"};
      printf("atol=%ld\t atof=%f\t atoi=%d\t\n",atol(a),atof(a),atoi(a));
  }
  </code></pre>
  
  <p>The output will be</p>
  
  <pre><code>atol=2545 atof=2545.965000 atoi=2545
  
  char a[]={“heyyou”};
  </code></pre>
  
  <p>Now when you run the program the following will be the output (<strong>why?</strong>, is there any solution to convert pure strings to integer?)</p>
  
  <pre><code>atol=0 atof=0 atoi=0
  </code></pre>
  
  <p>The string should contain the numeric value. Now modify this program as</p>
  
  <pre><code>char a[]={“007hey”};
  </code></pre>
  
  <p>The output in this case (tested in Red Hat Linux) will be</p>
  
  <pre><code>atol=7 atof=7.000000 atoi=7
  </code></pre>
  
  <p>so the functions have taken 007 only, not the remaining part (<strong>why?</strong>).</p>
  
  <p>Now consider this</p>
  
  <pre><code>char a[]={“hey007?};
  </code></pre>
  
  <p>The output of the program will be</p>
  
  <pre><code>atol=0 atof=0.000000 atoi=0
  </code></pre>
  
  <p>So I just want to convert my strings to numbers and then again to the same text. I played with these functions, and, as you see, I'm getting really interesting results.</p>
  
  <p>Why is that?</p>
  
  <p>Are there any other functions to convert from/to string/integer and vice versa?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>So as an input, if I take some names, or whatever, I will convert them to integers/floats... then apply some other functions.</p>
  
  <p>Also I'm curious about if I will take the same output with the same inputs when I use any of your suggestions?</p>