mgaikema icon

`getopt` example

mgaikema | PRO | 11/01/17 12:09:53 AM UTC | 0 ⭐ | 362 👁️ | Never ⏰ | []
C++ |

610 B

|

None

|

0 👍

/

0 👎

/*
    `getopt` example with defaults of `-s 524288*4` and `-b 128*2`.
*/
 
#include <getopt.h>
 
int main(int argc, char ** argv) 
{   
    int memory_size = 524288*4;
    int block_size = 128*2;
       
    int opt;
     
    while ((opt = getopt(argc, argv, "b:s:")) != -1) 
    {
        switch (opt) 
        {
            case 'b':
                block_size = atoi(optarg);
                break;
            case 's':
                memory_size = atoi(optarg);
                break;
            default:
                block_size = 128;
                memory_size = 524288;
        }
    }
}

Comments