Hi,
Code:
void check_activity(char * this_months, char * last_months)
{
FILE * fp1;
FILE * fp2;
int diff = 0;
int result = 0;
int countA = 0, countB = 0;
#ifdef DEBUG
printf("In check_activity().\n");
fflush(NULL);
#endif
if(!(fp1 = fopen(this_months, "r")))
error_func("In check_activity().", "Error : fopen(INPUT_FILE)", SYS | FATAL);
if(!(fp2 = fopen(last_months, "r")))
error_func("In check_activity().", "Error : fopen(OUTPUT_FILE)", SYS | FATAL);
/*
while(fscanf(fp1, "%d", &countA) != NULL)
;
while(fscanf(fp2, "%d", &countB) != NULL)
;
*/
if(fp1 != NULL)
{
/* Read the number of records */
fread(&countA, sizeof(int), 1, fp1);
fclose(fp1);
}
if(fp2 != NULL)
{
/* Read the number of records */
fread(&countB, sizeof(int), 1, fp2);
fclose(fp2);
}
diff = countA - countB;
fclose(fp1);
fclose(fp2);
printf("this month, last month, difference %d %d %d\n", countA, countB, diff);
#ifdef DEBUG
printf("Out check_activity().\n");
fflush(NULL);
#endif
}
I was hoping to establish the difference in the number of lines between two files, but as I have deliberately created two files which have 6 lines and 4 lines respectively, I was expecting an answer of 2
As _you_ will be able to see, that is not happening, perhaps you could tell me why please ?
tia,