title: How to parse integer command line arguments in C?
body: <p>I would like a user to pass either two parameters or leave it blank. For instance:</p>
  
  <pre><code>./program 50 50
  </code></pre>
  
  <p>or</p>
  
  <pre><code>./program
  </code></pre>
  
  <p>When I tried to use <code>int main(int argc, char *argv[])</code>, first thing I have done was to change <code>char *argv[]</code> to <code>int *argv[]</code> but it did not work. What I want is from the user is just <strong>to enter two integers between 0 and 100</strong>. So if it is not two integers then it should give an error.</p>
  
  <p>I was sort of thinking to give out an error with types (as I used to program on C#) but whatever I enter, argv[1] would be 'char' type all the time.</p>
  
  <p>So what I have done is </p>
  
  <pre><code>for (int i = 0; i &lt;= 100; i++) {
      //printf("%d", i);
      if (argv[1] == i) {
          argcheck++;
          printf("1st one %d\n", i);
      }
      else if (argv[2] == i) {
          argcheck++;
          printf("2nd one %d\n", i);
      }
  </code></pre>
  
  <p>This does not work as well. Also it gives warning when compiling, but if I change <code>argv</code> with <code>atoi(argv[1])</code> for instance, then it gives a <em>Segmentation fault (core dumped)</em> error.</p>
  
  <p>I need a simple way to solve this problem.</p>
  
  <p>EDIT:</p>
  
  <p>So I fixed with <code>atoi()</code>, the reason why it was giving segmentation fault was because I was trying it with null value when I have no parameter. So I fixed it up by adding an extra cond. But now the problem is if the value is let's say</p>
  
  <pre><code>./program asd asd
  </code></pre>
  
  <p>Then the output of <code>atoi(argv[1])</code> would be 0. Is there a way to change this value?</p>