Reputation: 133
I have two sets of data files "P" (position) and "F" (force) files. Separately (in two different codes) the codes can open and read all "P" and "F" files. When I try to read them together in single code, the code opens and reads data from files, but only 1004 of "P" file and then exits. I cannot even debug it as it shows a normal exit. What should I do to debug the code? The computer has enough memory and the data files are not large. Here is part of the code which opens the files:
...
FILE *finput1, *finput2;
char filename[160], filename2[160];
...
for (i=0;i<N_f1;i++) {
sprintf(filename, "F%d.dat", i);
finput1=fopen(filename,"r");
if( finput1 == NULL ) {
printf(" Could not open F file!\n");
return 0;
}
sprintf(filename2, "P%d.dat", i);
finput2=fopen(filename2,"r");
if( finput2 == NULL ) {
printf(" Could not open P file! %d \n",i);
return 0;
}
...
Upvotes: 2
Views: 58
Reputation: 122503
The files that can be open simultaneously is limited, you can check the value of FOPEN_MAX
in stdio.h
.
Note that it is the minimum number of files that the implementation guarantees, you might open more than it in practice.
Upvotes: 2
Reputation: 997
You are running into a maximum number of file descriptors. Close each file after you open the next one.
Upvotes: 4