Advertisement
d1cor

getopt.c

Sep 15th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. /*******************************************
  2. * Author     : Diego Cordoba / @d1cor      *
  3. * Purpose    : juncotic.com - JuncoTIC     *
  4. * Contact    : diego@juncotic.com          *
  5. *******************************************/
  6.  
  7. #include<stdio.h>
  8. #include<stdlib.h>
  9. #include<sys/types.h>
  10. #include<sys/stat.h>
  11. #include<unistd.h>
  12. #include<dirent.h>
  13. #include<fcntl.h>
  14. #include<errno.h>
  15. int main(int argc, char** argv) {
  16.  
  17.     int i=0;
  18.     char c;
  19.     opterr=0;
  20.     printf("Cantidad de argumentos: %d\n",argc);
  21.  
  22.     for(i=0;i<argc;i++){
  23.         printf("(%d)---> %s\n",i,*(argv+i));
  24.     }
  25.  
  26.     while((c=getopt(argc, argv, "abc:"))!=-1){
  27.         switch(c){
  28.         case 'a':
  29.             printf("Un caracter 'a'\n");
  30.             break;
  31.         case 'b':
  32.             printf("Un caracter 'b'\n");
  33.             break;
  34.         case 'c':
  35.             printf("Un caracter 'c' con argumento %s\n",optarg);
  36.             break;
  37.         default:
  38.             printf("Error de lectura\n");
  39.         }
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement