blob: 4b5fe6cbfd8d9fb20137ae67512bd2b488b020e9 [file]
<html lang="en">
<head>
<title>atof - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib">
<link rel="prev" href="atexit.html#atexit" title="atexit">
<link rel="next" href="atoi.html#atoi" title="atoi">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="atof"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="atoi.html#atoi">atoi</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="atexit.html#atexit">atexit</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a>
<hr>
</div>
<h3 class="section">2.7 <code>atof</code>, <code>atoff</code>&mdash;string to double or float</h3>
<p><a name="index-atof-8"></a><a name="index-atoff-9"></a><strong>Synopsis</strong>
<pre class="example"> #include &lt;stdlib.h&gt;
double atof(const char *<var>s</var>);
float atoff(const char *<var>s</var>);
</pre>
<p><strong>Description</strong><br>
<code>atof</code> converts the initial portion of a string to a <code>double</code>.
<code>atoff</code> converts the initial portion of a string to a <code>float</code>.
<p>The functions parse the character string <var>s</var>,
locating a substring which can be converted to a floating-point
value. The substring must match the format:
<pre class="smallexample"> [+|-]<var>digits</var>[.][<var>digits</var>][(e|E)[+|-]<var>digits</var>]
</pre>
<p>The substring converted is the longest initial
fragment of <var>s</var> that has the expected format, beginning with
the first non-whitespace character. The substring
is empty if <code>str</code> is empty, consists entirely
of whitespace, or if the first non-whitespace character is
something other than <code>+</code>, <code>-</code>, <code>.</code>, or a digit.
<p><code>atof(</code><var>s</var><code>)</code> is implemented as <code>strtod(</code><var>s</var><code>, NULL)</code>.
<code>atoff(</code><var>s</var><code>)</code> is implemented as <code>strtof(</code><var>s</var><code>, NULL)</code>.
<p><br>
<strong>Returns</strong><br>
<code>atof</code> returns the converted substring value, if any, as a
<code>double</code>; or <code>0.0</code>, if no conversion could be performed.
If the correct value is out of the range of representable values, plus
or minus <code>HUGE_VAL</code> is returned, and <code>ERANGE</code> is stored in
<code>errno</code>.
If the correct value would cause underflow, <code>0.0</code> is returned
and <code>ERANGE</code> is stored in <code>errno</code>.
<p><code>atoff</code> obeys the same rules as <code>atof</code>, except that it
returns a <code>float</code>.
<p><br>
<strong>Portability</strong><br>
<code>atof</code> is ANSI C. <code>atof</code>, <code>atoi</code>, and <code>atol</code> are subsumed by <code>strod</code>
and <code>strol</code>, but are used extensively in existing code. These functions are
less reliable, but may be faster if the argument is verified to be in a valid
range.
<p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
<code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
<p><br>
</body></html>