title: how to handle character from getopt
body: <p>I am not sure where i am missing. I want to catch some characters from command line. I am using getopt but not sure how to copy from optarg. Please help me i am not very sure about character/string handling in c.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;getopt.h&gt;
  
  main(int argc , char *argv[]) {
      char *file;
      int opt;
      while ( ( opt = getopt(argc, argv, "f:") ) != -1 ){
      switch(opt){
          case 'f':
          file=(char *) malloc(2);
          strcpy(file,optarg);
          printf("\nValue of file is %c\n",file);
      break;
      default :
      return(1);
      }
  }
  return(0);
  }
  </code></pre>