C language: time off

Time off to write a small program, you can turn off the computer immediately, or shut down the computer after a period of time.

system () command

code implements:

 
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. int main ()
  6. {
  7. char cmd[20]="shutdown -s -t ";
  8. char t[5]="0";
  9. int c;
  10.  
  11. system ( "title C language program shutdown"); // set up the cmd window title
  12. System ( "Lines MODE CON cols = 48 = 25"); // Window Width Height
  13. System ( "Color F0"); // can be written to call up the red color group
  14. system("date /T");
  15. system("TIME /T");
  16.  
  17. printf ( "----------- C language shutdown procedures ----------- \ n");
  18. the printf ( " 1. achieved in 10 minutes and closing timing of the computer \ n");
  19. printf ( " 2. Immediately turn off your computer \ n");
  20. printf ( " 3. Log off the computer \ n");
  21. printf ( " 0. exit the system \ n");
  22. printf("-------------------------------------\n");
  23.  
  24. scanf("%d",&c);
  25. switch(c) {
  26. case 1:
  27. printf ( "You want to automatically shut down the computer after the number of seconds (0 ~ \ n 600)?");
  28. scanf("%s",t);
  29. system(strcat(cmd,t));
  30. break;
  31. case 2:
  32. system("shutdown -p");
  33. break;
  34. case 3:
  35. system("shutdown -l");
  36. break;
  37. case 0:
  38. break;
  39. default:
  40. printf("Error!\n");
  41. }
  42. system("pause");
  43. return 0;
  44. }

While this program has little practical value, but allows us to understand the system () function.

Under Windows, system () function can perform dos command; in Unix / Linux can be performed Shell.

The program was run on Windows, a program for setting up and shutdown dos interface is through the dos command to achieve.

Guess you like

Origin blog.csdn.net/weixin_44015669/article/details/92674259