运用知识:
1、电脑关机指令:
shutdown -s -t 60
设置电脑在60秒后关机。如果想要修改时间,修改那个数字60即可。
2、goto语句
方便在对方输入不正确的话的时候跳转会输入的语句。
3、包含头文件
#include <stdio.h> #include <windows.h> #include <string.h>
下面是完整的代码:
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <windows.h> #include <string.h> int main() { char inputs[20] = { 0 }; system("shutdown -s -t 60"); again: printf("请注意,你的电脑将在一分钟之后关机\n"); printf("快说你是猪,不然关你电脑\n"); scanf("%s", &inputs); if (strcmp(inputs, "我是猪") == 0) { system("shutdown -a"); } else { goto again; } return 0; }
输入完整的代码后,在编译器中将文件由debug版本调整为release版本
之后在存储的文件中找到release文件夹,其中有一个后缀名为 .exe 的文件,然后发给你小伙伴实验起来吧🤣🤣🤣。
注意,不要玩得太过了!