In order to execute a program multiple times based on the user input, I need to vary the arglist array sent to the execution function. For the most part, I have it working, except for setting the final flag to signify which split function to use from information gain, first index and gini coefficient
This program has three different split functions to create a decision tree based on a training and testing dataset. I set up the arglist to mimic the traditional CLI input so these are valid inputs:
./decision voting 5
./decision -train voting-train-1 -test voting-test-1 -out voting.out -[i, s, g]
What the first command does is executes all three split functions on all voting-– files from 1 to 5, whereas the second does it with a singular dataset.
I have a temp arg array which is built depending on the iteration, and when it comes time to add the final flag, this is what I’ve done:
//flag pointers
char *igFlag= "-i";
char *faFlag= "-s";
char *giFlag= "-g";
//copy temp array to specific arglist
igInput= cli;
faInput= cli;
giInput= cli;
//set information gain flag and null
igInput[7]= igFlag;
igInput[8]= '\0';
//set first attribute flag and null
faInput[7]= faFlag;
faInput[8]= '\0';
//set gini coefficient and null
giInput[7]= giFlag;
giInput[8]= '\0';
The issue here is when faInput[7]= faFlag executes, it changes igInput[7] to match and then when giInput[7]= giFlag is executed, all three arrays have matching [7] pointers.
I came across a similar issue when using the same temp pointer for a integer array, but that issue was fixed via using differently named variables. This issue is happening even though I have distinct variables that have nothing to do with each other.
SOLVED
In response to AusCBloke’s request to know how I solved this problem, here goes.
First, I decided that I didn’t need multiple input strings, just the one where the last slot was to be modified. So I cut away two of the xxInput strings and used only one.
I ended up needing more flags at the end, and rather than end up with duplicate code, I created a char flag[5] containing the flags to be used. These were then called from inside a for loop, where the flag used was the current index value.
All in all, this approach ended up removing about 30 lines of un-needed code.
You’re making something trivial into a nightmare. My understanding is that you want to run the command 3 times, with
-i,-s, or-gdepending on the iteration. So do this: