I'm sorry for the confusion. My program may be a little messy, I sometimes use english variable names and sometimes dutch, no particular reason, it just happens. I'll post them in english from now on to avoid confusion .
This is pretty much the whole program:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
long no_lines=0;
char *dummyline;
char *Combinations_systemname[84] = {"Black Hole - Carbon Star","Black Hole - Helium Star","Black Hole - Black Hole", and a whole lot more combinations.......};
//********************
//Functions:
//********************
int Linecount(char* filename_array[],int n){
char filename[100];
no_lines=0;
sprintf(filename, "%s.txt", filename_array[n]);
FILE* file = fopen(filename,"r");
if (file!=NULL){
char dummyline[1000];
while ( fgets(dummyline, 1000, 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
fclose(file);
return no_lines;
} else {printf("!! %s File not available\n",filename);
return no_lines=0;
}
}
//********************
//Main Program
//********************
int main (){
int no_of_systems=0;
FILE* No_binarysystems_file = fopen("Aantal_dubbelsterren.txt","w");
int i=0;
for (i=0;i<84;i++){
Linecount(Combinations_systemname,i);
no_of_systems = no_lines/3;
printf("no_lines=%d \n",no_lines);
printf("Number of systems of this type: %d\n\n",no_of_systems);
fprintf(No_binarysystems_file,"%s,%d\n",Combinations_systemname[i],no_of_systems);
}
fclose(No_binarysystems_file);
//================================================//
//to make sure window doesn't close right away.
#ifdef _WIN32
system("PAUSE");
#endif
return (0);
}
Meanwhile I've found a corrupt textfile and that one happend to be the one I tested if the number of systems was correct. Not much of a test! Anyway. It does seem to work afterall.