當前位置:首頁 » 編程語言 » 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界面。

熱點內容
sql加空格 發布:2025-07-01 04:09:38 瀏覽:576
如何關閉ftp防篡改 發布:2025-07-01 04:09:04 瀏覽:87
頑固的緩存 發布:2025-07-01 03:28:23 瀏覽:114
u盤插安卓手機上怎麼加密 發布:2025-07-01 03:09:19 瀏覽:90
php記住我 發布:2025-07-01 02:58:51 瀏覽:392
流媒體伺服器搭建php 發布:2025-07-01 02:54:24 瀏覽:371
我的世界伺服器地板方塊 發布:2025-07-01 02:41:35 瀏覽:565
魔域伺服器爆滿怎麼進 發布:2025-07-01 02:31:42 瀏覽:739
c語言統計字元出現的次數 發布:2025-07-01 02:27:24 瀏覽:242
江鈴福特主要有哪些車型以及配置 發布:2025-07-01 02:23:10 瀏覽:25