I am trying to initialize "argv" with the argument I want for this program while I am working on the rest of it.
You will understand my problem by reading my trial (which does not compile, naturally):
Both parameters of main() are modifiable, but the array referenced by the second parameter is not resizable. If someone called your program with one argument, you can't even access argv[3] and up. To substitute a different set of arguments, you have to repoint the whole argv at your own array of pointers, each pointing at your own string. And don't forget to provide the terminating entry (argv[argc]==NULL)
Or just get into the habit of converting main's arguments into a vector<strings> as Athar suggests, in which case this is trivial.
The <vector> trick seems to be working well until I use the following line to use some of the arguments as char array (I need this "temperature = 24.9" in this format): char cstr_temp[200]; sprintf(cstr_temp,"temperature = %s", argv[2]);
Do you know why and how argv[2] could fit in this?
Thanks
Ok thanks, and is there any possibility to initialize something like this: argv[1]="C:\\";
(which doesn't work :s), to something like that, directly on the same line: argv[1]=("C:\\").c_str();
?
I am sorry I started to be confusing, and to get confused with what I wrote... Here we go again:
The thing is that I need to be able to use args[2] as such, in char cstr_temp[200]; sprintf(cstr_temp,"temperature = %s", argv[2]) where argv[2]) is a char array.
(I am not allowed to change this part of the code)
And to do that, I need args[2] to be transformed into a char array, that is why I wanted to find an equivalent to args[2]=("24.9").c_str();. But if THIS is not possible,
Do you know why char* argv[2]=args[2].c_str(); doesn't seem to wanna work?
Because c_str() returns a pointer to const char. args[2].c_str() gives you a C string.
But this is pointless - you need to review the basics first (in particular std::string and C strings) before you touch any of this again.