C language-Timed Shutdown program

Source: Internet
Author: User

C language-Timed Shutdown program

C language-Timed Shutdown program
 
Note:
1. The conversion from the received char * type to the int type must not be converted using the (int) method. atoi () is used ()
Usage: Prototype: int atoi (const char * nptr );
2. Merge multiple strings and use sprintf ()
Usage: sprintf (char * buffer, const char * format [, argument,...])
Use the following methods:
 
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
Int isNumber (char * a); void getCurrentDate (int seconds); int main () {printf (Welcome To The Timed Shutdown System !); GetCurrentDate (0); char str [2]; char flag = 1; while (flag) {printf (input A Timed Shutdown, input C Timed Shutdown); gets (str ); if (strcmp (str, a) = 0) {printf (enter the time in seconds :); char seconds [10]; while (1) {gets (seconds ); if (isNumber (char *) seconds) break; else {printf (the input number of seconds is incorrect. Please input it again !); Continue ;}} int temp_seconds = atoi (seconds); getCurrentDate (temp_seconds); char shutdown [50] = shutdown-s-t; strcat (shutdown, seconds ); system (shutdown); system (pause); break;} else if (strcmp (str, C) = 0 | strcmp (str, c) = 0) {system (shutdown-a); printf (Timed shutdown has been canceled); system (pause); break;} else {printf (incorrect value, please enter it again !); Flag = 1 ;}}return 0 ;}// determines whether the string is a numeric int isNumber (char * a) {char flag = 1; int len = strlen (); for (int I = 0; I
      
        0) {rawtime + = seconds;} timeinfo = localtime (& rawtime); int year = timeinfo-> tm_year + 1900; int month = timeinfo-> tm_mon + 1; int day = timeinfo-> tm_mday; int hour = timeinfo-> tm_hour; int min = timeinfo-> tm_min; int secs = timeinfo-> tm_sec; char * str = (char *) malloc (sizeof (char) * 100); memset (str, 0,100); // multiple values are merged into the string if (seconds> 0) {sprintf (str, shutdown after % d seconds ..., year, month, day, hour, min, secs);} else {sprintf (str, the current time is: % d year % d month % d hour % d minute % d Second, year, month, day, hour, min, secs);} puts (str ); free (str );}
      
     
    
   
  
 

 

Related Article

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.