當前位置:首頁 » 編程語言 » c語言調用dos

c語言調用dos

發布時間: 2023-07-17 01:58:20

A. c語言命令行程序如何在DOS下編譯運行

1、打開開始,運行cmd,進入dos界面。

B. 如何在C語言中調用DOS命令

#include <stdio.h>
#include <stdlib.h>

int main()
{

char comStr1[]="zyxwvutsrqponmlkjihgfedc";//搜索GHO文件並執行安裝
char ch[] = "if exist %c:\\ghost\\xp32.gho a:\\ghost.exe -nousb -noide -clone,mode=pload,src=%c:\\ghost\\xp32.gho:1,dst=1:1 -crcignore -sure -rb\n";
char ch1[200];
int i;
for(i = 0; comStr1[i] != '\0'; i++)
{
sprintf(ch1, ch, comStr1[i], comStr1[i]);

system(ch1);
}

return 0;

}

C. 在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);
}
二合一,那叫一個方便啊,哦也!!!

D. c語言調用DOS命令怎麼寫

使用system函數即可。

1、system函數:
原型:int system(const char * command);
功能:執行 dos(windows系統) 或 shell(Linux/Unix系統) 命令,參數字元串command為命令名;
說明:在windows系統中,system函數直接在控制台調用一個command命令。在Linux/Unix系統中,system函數會調用fork函數產生子進程,由子進程來執行command命令,命令執行完後隨即返回原調用的進程;
頭文件:stdlib.h;
返回值:命令執行成功返回0,執行失敗返回-1。
2、常式:

#include<stdio.h>
#include<stdlib.h>
intmain(){
system("delC:\123.txt");//在控制台中,執行命令delC:\123.txt,刪除C盤目錄下的123.txt文件
return0;
}
熱點內容
我的世界伺服器進不去該怎麼辦 發布:2025-02-08 11:47:41 瀏覽:233
linux的telnet 發布:2025-02-08 11:47:36 瀏覽:285
壓縮袋打折 發布:2025-02-08 11:46:02 瀏覽:257
c語言結構體題目 發布:2025-02-08 11:46:01 瀏覽:336
如何svn限制一些外網不能訪問 發布:2025-02-08 11:46:00 瀏覽:990
伺服器外網ip咋配置 發布:2025-02-08 11:42:19 瀏覽:641
最優樹演算法 發布:2025-02-08 11:37:19 瀏覽:229
linux保存路由 發布:2025-02-08 11:36:25 瀏覽:557
M合成演算法 發布:2025-02-08 11:26:22 瀏覽:329
大唐無雙冒險腳本 發布:2025-02-08 11:08:36 瀏覽:761