title: How do you use getopt() with non option arguments
body: <p>I am trying to use getopt() for a program that requires either an "e" or "d" option to select encrypt or decrypt then takes a key to be used for either on.  My problem is im not sure how to handle the key with getopt().  I have read much of of the man getopt() stuff and numerous other article at this point.  I currently get a floating point error and core dump and am recieveing the warning message:</p>
  
  <p>cypher.c: In function ‘main’: 
  cypher.c:14:3: warning: passing argument 2 of ‘getopt’ from incompatible pointer type [enabled by default] 
  /usr/include/getopt.h:152:12: note: expected ‘char * const*’ but argument is of type ‘char <em>*</em>’ 
  cypher.c:28:13: warning: assignment makes integer from pointer without a cast [enabled by default] </p>
  
  <p>Below is the actual code any help is appreciated.</p>
  
  <pre><code>include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  main(int argc, char **argv[]){
  
    int e,x; 
    int i=0;      
    int c=fgetc(stdin);
    //  int n=strlen(key);
    int encrypt;
  
    while((x = getopt (argc, argv, "ed")) != -1){
      switch (x){
      case 'e':
        encrypt=1;
        break;
      case 'd':
        encrypt=0;
        break;
      default:
        fputs("you broke it\n",stderr);
        exit(1);
      }
    }
      char key[100];
      key[100]= argv[optind++];
      int n = strlen(key);
  
      if(encrypt == 1){
        while(c != EOF){
           c= fgetc(stdin);
           e=(c - 32 + key[i % n]) % 95 +32;
           fputc( e, stdout);
           i++;
        }
      }
      else{
        while( e != EOF){
           c = fgetc(stdin);
           c=(e - 32 -key[i % n] +3 * 95) % 95 +32;
           fputc(c, stdout);
           i++;
        }
      }
    exit (0);
   }
  </code></pre>