Argument vector
Hello
I'm having trouble with reading from argument vector.
I'm setting up a kind of a debugging mode in my program and
I have this code
1 2 3 4 5 6 7 8 9
|
int main(int argc, char **argv){
int debugMode = 1;
if(strcmp(argv[1],"-d")==0){
debugMode = 1;
}
.
.
.
}
|
When I run my program with '-d' flag, it works fine.
When I run it without a flag, I get 'segmentation fault' error.
Any ideas why?
Thank you.
You try to access the second argument whether or not it is actually there. You need to check the number of arguments first.
Gotcha.
Thank you.
Topic archived. No new replies allowed.