Hi.
I'm developing a program on pattern recognition.
In it, I accept two input files (containing strings) from the user through the command line.
The input files, say input1.txt and input2.txt, are passed to a function processFiles(), which generates permutations of these strings and stores the resultant permutations in two new, generated files, say gen_file1 and gen_file2.
Immediately after the processFiles() routine is called, I continue by reading gen_file1 and gen_file2.
Doing this is resulting in some funny behavior. I get a run time error sometimes and sometimes I don't get any output.
The construct of my program is something as follows:
I suspect that the compiler is performing the functions in a parallel fashion, i.e, one part is branching out to compute the processFiles() routine and the other is continuing with the serial execution of main().
In order to confirm my suspension, I did the two operations separately, i.e, i first called processFiles() through one program and then ran another program opening the generated files, and it works fine.
Any workaround for this situation? Anyway I can synchronize the operations after the processFiles() call?
Or is it something else, the problem?
I'm developing a program on pattern recognition.
In it, I accept two input files (containing strings) from the user through the command line.
The input files, say input1.txt and input2.txt, are passed to a function processFiles(), which generates permutations of these strings and stores the resultant permutations in two new, generated files, say gen_file1 and gen_file2.
Immediately after the processFiles() routine is called, I continue by reading gen_file1 and gen_file2.
Doing this is resulting in some funny behavior. I get a run time error sometimes and sometimes I don't get any output.
The construct of my program is something as follows:
Code:
int main(int argc, char* argv[])
{
....
processFiles(argv[1], argv[2])
FILE* file1 = fopen("gen_file1","r");
FILE* file2 = fopen("gen_file2","r");
...
...
processFiles(char* input1, char* input2)
{
FILE* file1 = fopen(input1,"r");
FILE* file2 = fopen(input2,"r");
/* Some operations */
FILE* file3 = fopen("gen_file1","w+");
FILE* file4 = fopen("gen_file2","w+");
/*Write operations..*/
}
}
In order to confirm my suspension, I did the two operations separately, i.e, i first called processFiles() through one program and then ran another program opening the generated files, and it works fine.
Any workaround for this situation? Anyway I can synchronize the operations after the processFiles() call?
Or is it something else, the problem?
Comment