enjunear
Advanced Member level 3
- Joined
- Dec 21, 2010
- Messages
- 960
- Helped
- 309
- Reputation
- 618
- Reaction score
- 303
- Trophy points
- 1,343
- Location
- USA, midwest
- Activity points
- 9,749
I'm working on a C program for a class and having trouble with the getopt routine at the front of the program. Here is that section of code:
If I run the program with flags -p 2000 -t foo, it only processes 'p', and skips all arguments after that. Also, if you run with -t foo -p 2000, it processes the 't', but skips the 'p'.
I figure this is something straightforward, I'm just not seeing the issue. I can't do a live debug, because the app needs to be compiled and run on a remote system.
Ideas? TIA
Code:
int i, done;
opterr = 0;
while ((i = getopt(argc, argv, "pft")) != -1)
{
switch (i)
{
case 't':
// this is a test flag to show how the flags work
// this will print out the parms
printf("%s\n", argv[optind]);
break;
case 'p':
// add code for the p flag set
port_num = atoi(argv[optind]);
break;
case 'f':
// add code for the f flag set
break;
case '?':
default:
done = 1;
break;
}
if (done) break;
}
I figure this is something straightforward, I'm just not seeing the issue. I can't do a live debug, because the app needs to be compiled and run on a remote system.
Ideas? TIA