i have a app that writes to an xml file using command line switches, what i would like to do is have several of the cases combine into one so i can use switch -v xxxxxx and each x (either 1 or 0) is a different line below is a better example of what i am trying to accomplish
i may be confusing both of us LOL, lets try this ..
i want to get rid of all those cases and only have 1 case
where when the exe is called with -v 000001
it will break apart the 000001 (six slots) to equal this
slot 1 = s_fileread
slot 2 = s_filewrite
... ect
and do the function as described...
does this make more sense ?
i will try your code, but i have to be honest im a c++ newb and not sure what to replace switch(...) with and in the else statment not sure if i need that as if the -v is not used it just continues. there are other cases that are required, would it help if i posted the code in its entirety?
Don't send me code by email. If it's too big to post here then it's probably too big for me to read. I don't really want to sift through pages and pages of code.
I learn by example. So why don't you give me an example problem and what you want the desired result to be, and then it'll be able to help more.
Your previous example was kind of unclear. From what it looks like... if the user inputs this: myprogram -v 000001 you want:
So these are 1 digit arguments? Why are you using strings, then... wouldn't it make more sense to use an int or char or something?
anyway... you can just take individual characters out of the "101010" argument and assign them to the appropriate variable:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// note this code assumes fileread, filewrite, etc are chars, not strings
// as in they hold a single character
// argv[i] is the commandline argument that contains the characters you want to break up:
// ie: "101010"
if(strlen(argv[i]) >= 6) // make sure it has enough digits
{
fileread = argv[i][0]; // take the first digit
filewrite = argv[i][1]; // then the next
//... // and so on
dirdelete = argv[i][5]; // until the last
}
else
{
// user didn't input at least 6 digits, give them an error or something
}