/* Filename : leapyear.c * Function Name: main * Written By : Prof. Kantila [kantila@gmail.com] * Purpose : Program to check the given year for leap year * Arguments : None, Ask interactively * Header files : stdio.h, leap.h */ #include <stdio.h> /*Standard Input/Output functions required */ #include "leap.h" /*leapf function is defined in this file */
/*main function, return integer but takes no argument*/ int main(void) { /*Declaration of local variable y1 to store year and assignment of initial value*/ int y1=1; /*Using unformated output function fputs, it takes two arguments, first is string and second in of type FILE *, here stderr*/ fputs("This will check the given year & display whether its a leap year or not...\n",stderr); /*For while loop, we must ensure that the initial value of test variable is not false (here y1 must not be 0) else the loop will never execute thats why, we have initialized the variable y1 to 1 at the time of declaration*/ while (y1!=0) { /*Using formatted output function fprintf, it takes one more argument than printf as the first argument of the type FILE *, here stderr*/ fprintf(stderr,"Input year to check : "); /*Using formatted input function fscanf to read an integer value from standard input stream, i.e. stdin - it also takes one more argument than scanf function as the first argument of type FILE * */ fscanf(stdin,"%i",&y1); /*fflush(FILE *) function clears (flushes) the specified stream This is used here to remove any unwanted data (garbage) from stdin stream*/ fflush(stdin); /*Testing wheather given year is a leap year or not*/ /*Body of if true condition begins here*/ fprintf(stdout,"Year %i is %s a leap year\n",y1,((leapf(y1))?"\b":"not")); } /*Body of the while loop ends here */ fprintf(stderr,"Thanks for using 'leapyear.exe' created at MEC, Bikaner.\n"); /*Above message will go to monitor - even if output is redirected because it is being send to standard error terminal not standard output*/ return 0; /*returning control back to Operating System */ }
|