1<html lang="en"> 2<head> 3<title>atoi - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib"> 9<link rel="prev" href="atof.html#atof" title="atof"> 10<link rel="next" href="atoll.html#atoll" title="atoll"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="atoi"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="atoll.html#atoll">atoll</a>, 31Previous: <a rel="previous" accesskey="p" href="atof.html#atof">atof</a>, 32Up: <a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a> 33<hr> 34</div> 35 36<h3 class="section">2.8 <code>atoi</code>, <code>atol</code>—string to integer</h3> 37 38<p><a name="index-atoi-10"></a><a name="index-atol-11"></a><a name="index-g_t_005fatoi_005fr-12"></a><a name="index-g_t_005fatol_005fr-13"></a><strong>Synopsis</strong> 39<pre class="example"> #include <stdlib.h> 40 int atoi(const char *<var>s</var>); 41 long atol(const char *<var>s</var>); 42 int _atoi_r(struct _reent *<var>ptr</var>, const char *<var>s</var>); 43 long _atol_r(struct _reent *<var>ptr</var>, const char *<var>s</var>); 44 45</pre> 46 <p><strong>Description</strong><br> 47<code>atoi</code> converts the initial portion of a string to an <code>int</code>. 48<code>atol</code> converts the initial portion of a string to a <code>long</code>. 49 50 <p><code>atoi(s)</code> is implemented as <code>(int)strtol(s, NULL, 10).</code> 51<code>atol(s)</code> is implemented as <code>strtol(s, NULL, 10).</code> 52 53 <p><code>_atoi_r</code> and <code>_atol_r</code> are reentrant versions of <code>atoi</code> and 54<code>atol</code> respectively, passing the reentrancy struct pointer. 55 56 <p><br> 57<strong>Returns</strong><br> 58The functions return the converted value, if any. If no conversion was 59made, <code>0</code> is returned. 60 61 <p><br> 62<strong>Portability</strong><br> 63<code>atoi</code>, <code>atol</code> are ANSI. 64 65 <p>No supporting OS subroutines are required. 66 67 <p><br> 68 69 </body></html> 70 71