开发者

Setting a value to true or false based on a command line parameter

I am stuck in a ver开发者_运维百科y tricky situation. I have to set a boolean value to true or false based on the argument on the command line. I have to supply an argument, -ds=rel and based on this value, the program will set it to true and false. I have used

if (strncmp(argv[argc_pnt], "draw", 4) == 0)
{
    rel = true;
}

Now I want that if I give -ds=draw at the command line it should set rel = true. That is, it should compare the value after equal to (=) and if it gets drawn, it should make it true. Else if I give anything else after -ds=, the rel value should be false.


static const char DS_ARG[] = "-ds=";
rel = false;

// …

if (strncmp(argv[i], DS_ARG, sizeof(DS_ARG) - 1) == 0) {
    // argv[i] begins with "-ds="
    if (strcmp(argv[i] + sizeof(DS_ARG) - 1, "draw") == 0) {
        // "-ds=" is followed by "draw"
        rel = true;
    } 
}


Something like rel=!strcmp(argument, "draw");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜