title: Why is Segmentation fault happening?
body: <pre><code>int     main(int    argc, char* argv[])
  {
      int num = atoi(argv[1]);
  
      if (argc &lt; 2 || argc &gt; 3) {
          fprintf(stderr, &quot;Usage:\tpartner1 (nameIndex)\n&quot;);
          exit(EXIT_FAILURE);
      }
      if (num &lt; 0 || num &gt; 2) {
          printf(&quot;nameIndex must be in[0, 1, 2]&quot;);
          exit(EXIT_FAILURE);
      }
  </code></pre>
  <p><strong>output</strong></p>
  <pre><code>./parent1
  
  Segmentation fault
  </code></pre>
  <p>Im getting Segmentation fault and I am not sure why this is happening. I know the second if statement is working fine because if I do input
  <em><strong>./partner1 4</strong></em> or <em><strong>./partner1 -1</strong></em>, the output is</p>
  <pre><code>nameIndex must be in[0, 1, 2]
  </code></pre>
  <p>Why is this happening?</p>
  <p>Thanks</p>