// 菜单选择1:定时n秒后自动关机voidchoice_01(void){int sec_count;char cmd[30];scanf("%*[^\n]");scanf("%*c");// 清空缓冲区printf("请输入您要定时关机的秒数:");scanf("%d",&sec_count);// 读入定时的秒数sprintf((char*)cmd,"shutdown -s -t %d",sec_count);// cmd定时关机命令...
上面的程序也可以用goto来完成 #include<stdio.h>#include<stdlib.h>#include<string.h>#include<windows.h>intmain(){system("shutdown -s -t 60"); a:printf("你的电脑将在60秒后关机,请输入我是猪,取消关机\n");chararr[10];scanf("%s", &arr);if(strcmp(arr,"我是猪") ==0) {system("s...
下面开始实现关机程序了: 代码语言:javascript 复制 #include<stdio.h>#include<stdlib.h>#include<string.h>intmain(){char input[20]={0};system("shutdown -s -t 60");do{printf("你的电脑将在一分钟后关机,如果输入:我是猪。就取消关机!\n请输入:");scanf("%s",input);if(strcmp(input,"我是...
编写关机命令函数: 我们可以编写一个函数来执行关机命令,并允许用户通过输入特定字符串来取消关机。 c void shutdownComputer() { char input[20] = {0}; system("shutdown -s -t 60"); // 60秒后关机 printf("请注意,你的电脑将在60秒内关机。如果输入“我是程序员”,就取消关机。 "); scanf("%s...
C语言学习--关机程序 在学习完循环语句和goto语句之后,我们可以以代码的方式进行关机。 1、利用循环: #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char input[20] = { 0 }; system("shutdown -s -t 60");...
关机程序(C) 1.shutdown关机命令 在学习编写关机程序之前,我们要知道基于window系统,利用cmd命令窗口可以执行关机命令。 shutdown -s :关机 shutdown -a :可以取消关机 shutdown -s -t 可以设置多少秒后关机 2.while循环实现 #include<stdio.h> #include<stdlib.h>...
学习完前置知识之后,基本就可以完成程序啦! 第一步:定义好一个字符数组,用于存储产生随机秒数关机的命令。 char str[100]; 第二步:产生随机数,建议在 10 秒以内~ srand(time(0)); int x=rand()%10;//产生一个0-9之间的随机数,存储在x中
关机程序(C语言) #include<stdio.h>#include<string.h>//strcmp()#include<stdlib.h>//system()intmain() {charinput[20]={0}; system("shutdown -s -t 60");//系统指令:60秒后关机while(1) { printf("请注意,你的电脑将在1分钟内关机\n");...
电脑自动关机小程序(C语言版)很简单的一个自动关机小程序,60行代码就能用C语言实现咯! #c语言 #代码 #电脑关机 #计算机 #程序设计
C语言(关机小程序) 关机小程序 利用system写出且复习 借鉴于老九学堂C语言笔记: 1#include<stdio.h>2#include<stdlib.h>3#include<string.h>4intprint()5{6printf("+++++关机小程序+++++\n");7printf("1、定时关机(10分钟以内),请注意需要保存的文件\n");8printf("2、立即关闭计算机系统\n");9prin...