title: Why is atoi giving me a segmentation fault?
body: <p>I have the following piece of code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main ( int argc, char *argv[] )
  {
      int M, N;
  
      M = 1;
      N = 1;
      curr = 1;
  
      if ( argv[1][0] == '-' )
      {
          curr = 2;
  
          char *a = argv[1][1];
          char *b = argv[1][3];
  
          M = atoi(a);
          N = atoi(b);
      }
  
      printf("%d\n%d", M, N);
  }
  </code></pre>
  
  <p>So, I pass this program something like this:</p>
  
  <pre><code>a.out -1,2
  </code></pre>
  
  <p>and instead of getting expected output</p>
  
  <blockquote>
    <p>1<br>
    2</p>
  </blockquote>
  
  <p>I get a segmentation fault. What gives?</p>