我只是想测试全局变量optind并做下面的测试。如何判断optind的价值?如何判断optind在getopt中的值
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
char optStr[] = "ab";
int c;
while ((c = getopt(argc, argv, optStr)) != -1) {
printf("optind: %d\n", optind);
switch (c) {
case 'a':
printf("-a\n");
break;
case 'b':
printf("-b\n");
break;
case '?':
printf("error\n");
break;
}
}
return 0;
}
./a.out -ab
OPTIND:1
-a
OPTIND:2
-b
下:
./a.out -a
OPTIND:2
-a
“法官”是什么意思? – immibis
@immibis optind的价值是什么?也许“评判”不是很准确。 – hel