Advertisement
mgaikema

`getopt` example

Oct 31st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. /*
  2.     `getopt` example with defaults of `-s 524288*4` and `-b 128*2`.
  3. */
  4.  
  5. #include <getopt.h>
  6.  
  7. int main(int argc, char ** argv)
  8. {  
  9.     int memory_size = 524288*4;
  10.     int block_size = 128*2;
  11.        
  12.     int opt;
  13.      
  14.     while ((opt = getopt(argc, argv, "b:s:")) != -1)
  15.     {
  16.         switch (opt)
  17.         {
  18.             case 'b':
  19.                 block_size = atoi(optarg);
  20.                 break;
  21.             case 's':
  22.                 memory_size = atoi(optarg);
  23.                 break;
  24.             default:
  25.                 block_size = 128;
  26.                 memory_size = 524288;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement