Hello, I find the value printed by gdb does not consist with the right value.The following is the output.
(gdb)
7 while ( ( optc = getopt(argc, argv, ":b:B:h" ) ) != -1 ) {
(gdb)
8 printf( "%c %d %s\n", optc, optind, optarg);
(gdb)
B 5 1-2
7 while ( ( optc = getopt(argc, argv, ":b:B:h" ) ) != -1 ) {
(gdb) p optind
$1 = 1
(gdb)
The optind printed on stdout is 5, however, it is 1 printed by gdb. What,s wrong?
my source file is:
#include <stdio.h>
#include <getopt.h>
void main( int argc, char** argv) {
int i = 0;
char optc = 0;
i = 1;
while ( ( optc = getopt(argc, argv, ":b:B:h" ) ) != -1 ) {
printf( "%c %d %s\n", optc, optind, optarg);
}
if (optind < argc) {
printf("non-option ARGV-elements: ");
while (optind < argc)
printf("%s ", argv[optind++]);
printf("\n");
}
}
Thanks!