First you need to call the header file #include<stdlib.h>
1. Set the cmd window title
system("title C语言关机程序");
2. Window width, height
system("mode con cols=48 lines=25");/
3. Set the color
system("color 1D");
The 1 behind the color is the background color code , and D is the foreground color code .
0 = black 8 = gray ("bright black")
1 = blue 9 = bright blue
2 = green A = bright green
3 = lake blue B = bright lake blue
4 = red C = bright red
5 = purple D = bright purple
6 = yellow E = bright yellow
7 = white F = bright white
4. Date
system("date /T");
5. time
system("TIME /T");
6. Timing 60 seconds to shut down
system("shutdown -s -t 60");
7. Cancel shutdown command
system("shutdown -a");
8. This function means to suspend , waiting for the user signal; otherwise, the console program will pass in a flash, and you will not have time to see the execution result.
system("pause");
9. Use C language to delete the file , for example, the location of the file is d:\123.txt and use the system() function to execute the windows command.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
system("del d:\\123.txt");
return 0;
}
Let's take a look at this program, can you understand it? If it can explain that you have learned it, if not, please take a look at the previous explanation
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int print()
{
printf(" ╪╪╪╪╪╪╧╧╧╧╧╧╧╧╪╪╪\n");
printf("╔═══╧╧C语言关机程序 ╧╧══╗\n");
printf("║※1.实现10分钟内的定时关闭计算机║\n");
printf("║※2.立即关闭计算机 ║\n");
printf("║※3.注销计算机 ║\n");
printf("║※4.退出系统 ║\n");
printf("╚════════════════╝\n");
return 0;
}
int main()
{
system("title C语言关机程序");//设置cmd窗口标题
system("mode con cols=48 lines=25");//窗口宽度高度
system("color 0B");
system("date /T");
system("TIME /T");
char cmd[20]="shutdown -s -t";
char t[5]="0";
print();
int c;
scanf("%d",&c);
getchar();
switch(c)
{
case 1:printf("您想在多少秒后自动关闭计算机?(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");
exit(0);
}