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:
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- int main ()
- {
- char cmd[20]="shutdown -s -t ";
- char t[5]="0";
- int c;
- system ( "title C language program shutdown"); // set up the cmd window title
- System ( "Lines MODE CON cols = 48 = 25"); // Window Width Height
- System ( "Color F0"); // can be written to call up the red color group
- system("date /T");
- system("TIME /T");
- printf ( "----------- C language shutdown procedures ----------- \ n");
- the printf ( " 1. achieved in 10 minutes and closing timing of the computer \ n");
- printf ( " 2. Immediately turn off your computer \ n");
- printf ( " 3. Log off the computer \ n");
- printf ( " 0. exit the system \ n");
- printf("-------------------------------------\n");
- scanf("%d",&c);
- switch(c) {
- case 1:
- printf ( "You want to automatically shut down the computer after the number of seconds (0 ~ \ n 600)?");
- scanf("%s",t);
- system(strcat(cmd,t));
- break;
- case 2:
- system("shutdown -p");
- break;
- case 3:
- system("shutdown -l");
- break;
- case 0:
- break;
- default:
- printf("Error!\n");
- }
- system("pause");
- return 0;
- }
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.