I've written the code to determine if a year is a leap year or not, reading from a file, and printing to a file, and telling how many years were checked. I'm having trouble figuring out how to convert it to utilizing functions in the program, for the actual calculations and the printing of the output. Any help here would be appreciated!
#include <stdio.h>
main()
{
int year, totalYears, e;
FILE*InFile, *OutFile;
InFile = fopen("data3.txt","r");
OutFile = fopen("out3.txt","w");
fprintf(OutFile, "Leap Year Check\n");
fprintf(OutFile, " Year Result\n");
totalYears = 0;
e=fscanf(InFile,"%d",&year);
/*
Calculate whether a year is a leap year or not.
*/
while (e==1)
if(year%400 == 0 || (year%100 != 0 && year%4 == 0))
{
fprintf(OutFile, " %d Leap Year\n",year);
e=fscanf(InFile,"%d",&year);
totalYears = totalYears + 1;
}
else
{
fprintf(OutFile, " %d Not Leap Year\n",year);
e=fscanf(InFile,"%d",&year);
totalYears = totalYears + 1;
}
fprintf(OutFile, "%d years were checked",totalYears);
fclose(InFile);
fclose(OutFile);
}