I have to pass system configurations details inside a function in c++ by making use of command line parameters (argv, argc). the function looks as follows:
function(char * array[]){
windows_details = array[1];
graphic_card = array[2];
ram_detail = array[3];
procesor_detail = array[4];
}
int main(int argc, char *argv[]){
char *array[] = { argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]};
function(array);
}
So, when i execute the program exe as follows i get the right output:
sample.exe windows_32bit nividia 5Gb i7processor
But my concern is every time values has to be in specific order i.e the user have to take care that "windows_details" will be the first comand line parameter then "graphic_card" and like wise the ram_details and processor_details ,so this solution is not robust i.e if the sequence of values are interchanged the result will not be right. I want the solution to be sequence independent,whatever be the sequence the values to be substituted at right place also the comand line arguments to be passed as values to options. e.g as follows:
sample.exe --configuration i7_processor 5GB windows_32bit nividia or
sample.exe --configuration 5GB i7_processor nividia windows_32bit or
sample.exe --configuration nividia windows_32bit 5GB i7_processor
.
.
So, like above there is option as "--configuration" and then the details in any sequence. I tried to add option part as follows but its not working:
int main(int argc, char *argv[]){
char *array[] = { argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]};
std::string arg = *(reinterpret_cast<std::string*>(&array));
if (arg == "--configuration"){
function(array);
}
else {
std::cout << "Usage " << argv[0] << "\t--config\t\t Specify the configuration of target" << std::endl;
return 1;
}
return 0;
}
So, please help me out in solving my problem. What shall i do to make it more robust along with addition of options?