title: How does atoi() actually work
body: <p><strong>This is the Code :</strong></p>
  
  <pre><code>#include &lt;ctype.h&gt;
  
  /* atoi:  convert s to integer; version 2 */
  int atoi(char s[])
  {
  int i, n, sign;
  
  for (i = 0; isspace(s[i]); i++)  /* skip white space */
      ;
  sign = (s[i] == '-') ? -1 : 1;
  if (s[i] == '+' || s[i] == '-')  /* skip sign */
      i++;
  for (n = 0; isdigit(s[i]); i++)
      n = 10 * n + (s[i] - '0');
  return sign * n;
  }
  </code></pre>
  
  <p>Q1) The first line of code counts white space? That means it counts spaces, enter, return etc? Say my string starts after two spaces is it? And after counting white spaces i value has been incremented?</p>
  
  <p>Q2) the next sign line calculates if string is like <code>-234</code>? or <code>234</code>?</p>
  
  <p>Q3) next line if it has <code>+</code> or <code>-</code> sign count them in <code>i</code> which has already been incremented by calculated white spaces? is it?</p>
  
  <p>Q4) next line calculates the number in the string say <code>234</code>. <code>n= 10*n+ ('2'-'0')</code> => <code>i</code> get <code>2</code> => <code>n</code>= <code>10*2 + ('3'-'0')</code> => <code>i</code> get <code>23</code> and at last <code>i</code> get number <code>234</code></p>
  
  <p>and in the last line multiply <code>234</code> with <code>-1</code> or <code>+1</code> whatever the answer is*</p>
  
  <p>Do I understand this code correctly?</p>