我需要我的程序从命令行中获取几个参数,语法如下:
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) 我有一个SQL Server,我所知道的是机器上没有ODBC数据源设置,我需要从C++连接到它.我有用户名和密码,如何连接到它?