谁能用C语言写出一个个程序,让电脑能够自动关机?

Python015

谁能用C语言写出一个个程序,让电脑能够自动关机?,第1张

可以的,给以下代码已经编译运行确认了(害得我关了一次机!)

#include<stdio.h>

#include<dos.h>

#include<stdlib.h>

void

main()

{

char

shut[8]

char

b[81]

printf("Hello,

Welcome

to

the

TC

automatic

shutdown

procedures\n")

printf("

Watermelon

production\n")

printf("Please

enter

your

desired

automatic

shutdown

of

time:")

scanf("%s",shut)

sprintf(b,"at

%s

shutdown

-s",shut)

system(b)

}

运行实例:

Hello,

Welcome

to

the

TC

automatic

shutdown

procedures

Watermelon

production

Please

enter

your

desired

automatic

shutdown

of

time:12:29

新加了一项作业,其作业

ID

=

1

可以通过C语言调用系统命令实现关机。

1、C语言可以通过system函数实现调用系统命令(shell 命令)。

system函数声明于stdlib.h, 形式为

int system(const char *cmd)

功能为执行cmd中的shell指令。

2、在windows中,关机命令为shutdown. 具体说明如图:

更多信息,可以命令行下输入shutdown /?查看。

3、从命令说明上可以得知,shutdown /s 即可实现关机效果。

4、参考代码:

#include <stdlib.h>

int main()

{

    system("shutdown /s")//调用关机命令。

    while(1)

}

5、注意事项:

该命令仅用于windows,如果要移植到其它操作系统,则需要适配目标系统的关机命令,如Linux的halt或shutdown -h。

1a字符串赋值a[20]={‘0’}

2scanf(“%s”,a)字符串赋值.不用循环

3字符串相等关系运算有特定函数可以实现,当然自己写也可以,不过你的写法有问题,c字符串不支持直接做关系运算

4 getch函数缺少头文件,if else,else选择可缺省 返回关键字使用也有问题

你这个程序我可以帮你写,不过功能是否能实现不确定,因为我也是半瓶水,最后的函数没用过。

最后再补充一点,你头文件引用语法就有错误,没有空格