新手感受编程的魅力
使用编程让电脑关机,这打破了我对编程的最初的影响。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
#include<string.h>
int main()
{
char a[10] = { 0 };
b:
system("shutdown -s -t 120");
printf("请注意您的电脑将在2分钟内关机");
scanf("%s", a);
if (0 == strcmp(a, "取消关机"))//strcmp 如果发现两个字符串相等 ,会返回0。strcmp 的库函数<string.h>
{
system("shutdown -a");
}
else
{
goto b;
}
return 0;
}
也可以使用循环去刷新
```c
define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
#include<string.h>
int main()
{
char input[20] = { 0 };
//怎么关机?
system("shutdown -s -t 120");
while (1)
{
// printf("请注意,你的电脑在2分钟内关机,如果输入:我是猪,就取消关机\n");
scanf("%s", input);
//strcmp 如果发现两个字符串相等,会返回0
if (0 == strcmp(input, "我是猪"))//两个字符串,能使用==比较大小吗?不能!应用使用strcmp-比较字符串大小的库函数
{
system("shutdown -a");
break;
}
}
return 0;
}
这一编程操作下来让我感受到编程不仅仅是刻板的敲代码;它能使系统发生改变。电脑病毒的产生就有迹可循了。