C Language Applet calculates the date of the second day sample code

Source: Internet
Author: User
Enter a date to determine which day the next date is, and if the date is entered incorrectly, invoke the CAL command under Linux to display the entered month copy code code as follows:


#include <stdio.h>


#include <stdlib.h>


#include <string.h>


#include <time.h>


int, month, day;


const int day_30 = 30;


const int day_31 = 31;


int day_month_2 = 0;


char err_flag = 0;


void Compute ()


{


printf ("Enter Month Day (1992-7-19):");


scanf ("%d-%d-%d", &year, &month, &day);


if (year%4==0 && year%100!=0) | | (year%400==0))


 {


day_month_2 = 29;


 }


Else


 {


day_month_2 = 28;


 }


if (month>=1 && month<=12)


{


if (month = 2)


  {


if (Day > day_month_2)


   {


Err_flag = 1;


   }


else if (day = = day_month_2)


   {


month++;


day = 1;


   }


Else


   {


day++;


   }


  }


else if (month==1 | | month==3 | | month==5 | | month==7 | |


Month==8 | | month==10 | | MONTH==12)


  {


if (Day > Day_31)


   {


Err_flag = 1;


   }


else if (day = = day_31)


   {


month++;


day = 1;


   }


Else


   {


day++;


   }


  }


Else


  {


if (Day > Day_30)


   {


Err_flag = 1;


   }


else if (day = = day_30)


   {


month++;


day = 1;


   }


Else


   {


day++;


   }


  }


if (Month > 12)


  {


year++;


month = 1;


  }


 }


Else


 {


Err_flag = 1;


 }


}


int main ()


{


time_t now;


Char ch, c;


Char call_cal[30];


do


 {


compute ();


if (err_flag)


  {


err_flag = 0;


printf ("Date input error, call Cal Command query%d years%d months: nn", year, month);


sprintf (call_cal, "/usr/bin/cal%d%d", month, year);


system (call_cal);


//system ("clear");


while ((C=getchar ())!= ' n ' && (C=getchar ())!=eof);


printf ("Re-enter (y/n):");


  }


Else


  {


printf ("The next day is%d-%d-%d.") N ", year, month, day);


while ((C=getchar ())!= ' n ' && (C=getchar ())!=eof);


printf ("Enter the date Again (y/n):");


  }


ch = getchar ();


 }


while (ch== ' y ' | | | | ch== ' y ' | | | ch== ' n ');


time (&now);


printf ("Now is%s", CTime (&now));


puts ("having a goodday!");


return 0;


}  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.