Write a timer shutdown program, you can immediately shut down the computer, you can also turn off the computer after a period of time.
The system () command is mainly examined here.
Code implementation:
#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 Shutdown procedure"); Set CMD window title
system ("mode con cols=48 lines=25");//Window width height
system ("Color F0");//Can be written as red. Color Group
System (" Date/t ");
System ("time/t");
printf ("-----------C language shutdown program-----------\ n");
printf ("1. Implement a timed shutdown of the computer within 10 minutes \ n");
printf ("2. Turn off the computer immediately \ n");
printf ("3. Log off of the computer \ n");
printf ("0. Exit system \ n");
printf ("-------------------------------------\ n");
scanf ("%d", &c);
Switch (c) {case
1:
printf ("How many seconds do you want to turn off the computer automatically?") (0~600) \ n ");
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;
}
This program is not very useful, but it allows us to understand the system () function.
Under Windows, the System () function can execute a DOS command; in Unix/linux, you can execute the shell.
Please run the above program under Windows. The DOS interface settings and shutdown functions are implemented through DOS commands in the program.