小编Sal*_*der的帖子

解析具有多个参数的命令行选项[getopt?]

我需要我的程序从命令行中获取几个参数,语法如下:

getpwd -l user1 user2 ... -L -X -S...
Run Code Online (Sandbox Code Playgroud)

所以,我需要让用户背后的-l选项.我尝试过使用getopt,但没有太多运气,只有当我将其他选项放在-l:

getpwd -L -X -S ... -l user1 user2 ...
Run Code Online (Sandbox Code Playgroud)

我的代码(for -l-S):

    while((c = getopt(argc, argv, "l:S")) != -1){
    switch(c){
        case 'l':
            index = optind-1;
            while(index < argc){
                next = strdup(argv[index]); /* get login */
                index++;
                if(next[0] != '-'){         /* check if optarg is next switch */
                    login[lcount++] = next;
                }
                else break;
            }
            break;
        case 'S':
            sflag++;                        /* other option */ …
Run Code Online (Sandbox Code Playgroud)

c parsing command-line-arguments

16
推荐指数
1
解决办法
2万
查看次数

如何在没有ODBC的情况下从C++连接到SQL Server?

我有一个SQL Server,我所知道的是机器上没有ODBC数据源设置,我需要从C++连接到它.我有用户名和密码,如何连接到它?

c++ sql-server

1
推荐指数
1
解决办法
3235
查看次数

标签 统计

c ×1

c++ ×1

command-line-arguments ×1

parsing ×1

sql-server ×1