当前位置:首页 » 编程语言 » 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界面。

热点内容
走心机编程教学 发布:2025-07-01 15:34:30 浏览:219
安卓系统哪个bug最少 发布:2025-07-01 15:34:16 浏览:777
不是安卓怎么让时间显示在屏幕上 发布:2025-07-01 15:20:54 浏览:509
黄岩数控编程培训 发布:2025-07-01 15:12:30 浏览:979
迷宫寻路算法 发布:2025-07-01 15:12:29 浏览:544
微信视频缓存目录 发布:2025-07-01 14:58:59 浏览:393
vmwarelinux教程 发布:2025-07-01 14:50:33 浏览:498
名词解释预算法 发布:2025-07-01 14:34:36 浏览:918
iis文件拒绝访问 发布:2025-07-01 14:34:20 浏览:570
苹果和安卓相比哪个游戏多 发布:2025-07-01 14:24:16 浏览:762