当前位置:首页 » 编程语言 » c语言在dos下运行

c语言在dos下运行

发布时间: 2024-03-27 03:43:52

㈠ 在c语言中如何使用dos命令

用system()函数
原型:int
system(char
*cmd)
包含在dos.h下(VC
包含在stdlib.h)

定时关机
程序:
#include<stdio.h>
#include<dos.h>
#include<string.h>
void
main()
{
char
s[30]="shutdown
-s
-t
";
char
*p;
printf("please
input
how
many
seconds
you
want
to
wait
:
");
scanf("%s",p);
strcat(s,p);
system(s);
}
需要注意的是,上面的程序需在Turbo
C小编译,在VC环境下会提示error
C2065:
'system'
:
undeclared
identifier
可以改为:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int
main()
{
char
p[100]="shutdown
-s
-t
";
char
s[20];//注意这里不能写成*s否则即使调试成功,程序写无法正常运行!
int
str;
int
ch;
printf("请输入
等待时间
(秒):");
scanf("%s",s);
strcat(p,s);
system(p);
return
0;
}
一旦编译成功后就可以在工程文件夹下找到生成的*.exe
文件,以后就不用那么麻烦的键入命令啦,呵呵……
如果想取消关机,可另外在写一个程序:
#include<stdio.h>
#include<dos.h>
#include<string.h>
void
main()
{
char
s[30]="shutdown
-a
";
system(s);
}
二合一,那叫一个方便啊,哦也!!!

㈡ c语言命令行程序如何在DOS下编译运行

1、打开开始,运行cmd,进入dos界面。

热点内容
挖矿app源码 发布:2025-09-11 09:49:38 浏览:237
服务器怎么添加3个ip 发布:2025-09-11 09:06:57 浏览:60
安卓手机直播键在哪里 发布:2025-09-11 09:03:22 浏览:28
bat文件夹 发布:2025-09-11 08:36:36 浏览:423
第一款安卓机是什么 发布:2025-09-11 08:32:54 浏览:147
服务器类型云服务器 发布:2025-09-11 08:13:07 浏览:904
编译程序变可执行文件 发布:2025-09-11 08:12:09 浏览:813
关闭优化存储空间 发布:2025-09-11 08:08:10 浏览:292
迈拓z1固态缓存 发布:2025-09-11 07:51:09 浏览:505
银联在线支付接口php 发布:2025-09-11 07:50:24 浏览:502