Today for everyone to bring two a C language Small program sharing, the need for practical application of the role is not very small, but it is definitely helpful to you! In the future, the small series will be regularly released some: a C language Small program source code + comments + answers, to enrich everyone's knowledge!
#include <stdio.h>
#include <string.h>
#include <stdlid.h>
void Main ()
{
Char cmd[20]= "shutdown-s-T";
Char t[5]= "0";
int C;
System ("Title C language Shutdown program"); Set CMD Window caption
System ("mode con cols=48 lines=25"); Window width Height
System ("Color F0"); You can write red to bring up the color group
System ("date/t");
System ("time/t");
printf ("-----------C language shutdown program-----------\ n");
printf ("1. Achieve a timed shutdown of the computer within 10 minutes \ n");
printf ("2. Turn off the computer immediately \ n");
printf ("3. Log off 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 of little practical value, but it allows us to understand the system () function. Under Windows, the System () function can execute DOS commands, and in Unix/linux, the shell can be executed. Please run the above program under Windows. In the program, the DOS interface is set up and the shutdown function is implemented by DOS command.
C. C + + Tutorial: C Language timed off applet