I have been trying to develop a program that will calculate distances, mass, volume and others, but I am stuck at programming the switches, you know like in this:
ping google.com -t -l 500
I have created the batch file that will create the classpath and path variables. I just have to get something like:
calc volume -u mm -l 500 -w 333 -h 7853
I have no idea how to do that, is it short, or is it tons of lines?
int main ( int argc, char **argv )
{
// you can use argc, argv in here
}
argc is the number of arguments passed
argv is an array of C strings holding the argument values
argv[0] is always the name of your program
argv[i] is the ith argument
I did that, but I cannot get things like
-t -l -v -atr -i -cant -get -this -to -work
if tried to put, argv[v] and like that, and I cannot get it to work
int main(int argc,char* argv[]){
//compare the strings - make sure the value is logically negated
//because strcmp returns 0 when they're the same
if(!strcmp(argv[1],"-myswitch")){
/*do stuff*/}
return 0;}
int main(int argc,char* argv[])
{
// args start at 1 (0 is program name)
for(int i = 1; i < argc; ++i) // index every arg in argv[]
{
if(std::string(argv[i]) == "-w") // test each arg against our switch
{
// found -w ...
}
}
}