Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <getopt.h>
  3. int main ( int argc, char **argv) {
  4.  int option_index = 0;
  5.  char *user_name = NULL;
  6.  while (( option_index = getopt(argc, argv, "u:g")) != -1){
  7.    switch (option_index) {
  8.      case 'u':
  9.       user_name = optarg;
  10.        printf("User is selected\n");
  11.        printf("The user is %s\n",user_name);
  12.        break;
  13.      case 'g':
  14.        printf("Group is selected\n");
  15.        break;
  16.      default:
  17.       printf("Option incorrect\n");
  18.       return 1;
  19.      } //end block for switch
  20.    }  //end block for while
  21.  return 0;
  22. } // end main block
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement