title: Assigning optarg to an int in C
body: <p>I am trying to assign an optarg value to an int, but the compiler gives me the following warning:</p>
  
  <pre><code>warning: assignment makes integer from pointer without a cast [enabled by default]
  </code></pre>
  
  <p>I have tried casting optarg as int before the assignment</p>
  
  <pre><code>n = (int) optarg;
  </code></pre>
  
  <p>but still get a warning:</p>
  
  <pre><code>warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  </code></pre>
  
  <p>I am not sure what needs to be done before I can simply assign the optarg to an integer, then print it (for now).</p>
  
  <pre><code>int main (int argc, char *argv[])
  {
    char c;
    int n;
  
    while ((c = getopt(argc, argv, "m:")) != -1) {
      switch (c) {
      case 'm':
        n = optarg;
        break;
      }
    }
  
    printf("%d\n", n);
  
    return 0;
  }
  </code></pre>