I have 47 different files:
- 001_template.dat
- ...
- 047_template.dat
in a directory called /data. I need to compare each of these template files to three different query files, also in the directory. These are named:
- 001_AU01_query.dat
- 001_AU12_query.dat
- 001_AU17_query.dat.
I know how to get all of this to run, but I will have to cut and paste these 6 lines of code 46 more times and the program will get very long and confusing.
Is there a good way to loop over these files? Possibly by looping over the template files and then doing three queries for every template? I obviously have a similarity function and a sort function already defined, as well as inputFile
. Here is the code I would like to convert: (not homework this is for a facial expression recognition project I have been working on)
int main()
{
vector<float> temp01;
vector<float> temp12;
vector<float> temp17;
temp01 = similar(inputFile("data/001_AU01_query.dat"), inputFile("data/001_template.dat"));
sortAndOutput(temp01);
temp12 = similar(inputFile("data/001_AU12_query.dat"), inputFile("data/001_template.dat"));
sortAndOutput(temp12);
temp17 = similar(inputFile("data/001_AU17_query.dat"), inputFile("data/001_template.dat"));
sortAndOutput(temp17);
}
Use two arrays holding the names of files and templates and loop on them:
and loop on them:
Then I would go with creating the file names with sprintf into the loop:
That should work as expected I think.