I've just tested it a little more and the problem seems to be the number of lines. Sometimes it counts the right number and sometimes it doesn't, strange. I would expect it to either work or not work at all.
This is my function for counting the lines:
Code:
int Linecount(char* filename_array[],int n){
char filename[100];
sprintf(filename, "%s.txt", filename_array[n]);
FILE* file = fopen(filename,"r");
if (file!=NULL){
//dummyline = (char*) malloc (100);
char dummyline[100];
while ( fgets(dummyline, 100, file) != NULL) no_lines++;
printf("Scanned: %s\n",filename); //testing filename
printf("%s",dummyline); //just for testing if last line in the file is indeed from the correct file
return no_lines;
free (dummyline);
fclose(file);
} else {printf("!! %s Staat er niet bij\n",filename);
return no_lines=0;
}
}
It reads the correct files, i could see that by showing the dummyline, which is the last line of the file (After its finished counting). So what's going wrong during the counting of some files??