0

How to get more than one char in getopt? eg -abc option -bcd another_option

My origianl code:

while((opt = getopt(argc, argv, "ild:r:R:")) != -1){

    switch(opt){
        case 'd':   //Do STH
                    break;

        case 'i':   //Do STH
                    break;

        case 'l':   //Do STH
                    break;   
        case 'R':
        case 'r':   //Do STH                            
                    break;
                    default:    return -1;
    }
}

However, it is not available for more than one character eg -abc or -bcd What should I do for it? Any comment?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Question-er XDD
  • 640
  • 3
  • 12
  • 27
  • 2
    Have a look at getopt_long (http://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html). Note that long parameters should use `--foo` instead of `-foo`. Also, with default getopt, because `-` implies a single character, `-abc` actually means `-a -b -c`. – slugonamission Sep 21 '15 at 08:44
  • @Gombat, that question is about getopt from bash, this is about getopt from c. – gavv Sep 21 '15 at 08:49
  • @g-v: I removed the flag. Nevertheless, it was the same answer. – Gombat Sep 21 '15 at 08:51

0 Answers0