當前位置:首頁 » 編程語言 » 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-05-15 20:17:28 瀏覽:814
幼兒速演算法 發布:2025-05-15 20:15:08 瀏覽:86
best把槍密碼多少 發布:2025-05-15 20:13:42 瀏覽:548
android安裝程序 發布:2025-05-15 20:13:20 瀏覽:559
c語言跳出死循環 發布:2025-05-15 20:06:04 瀏覽:824
a19處理器相當於安卓哪個水平 發布:2025-05-15 20:05:29 瀏覽:639
榮耀9i安卓強行關機按哪個鍵 發布:2025-05-15 20:00:32 瀏覽:750
密碼鎖寫什麼最好 發布:2025-05-15 19:05:31 瀏覽:782
5的源碼是 發布:2025-05-15 19:04:07 瀏覽:719
c語言創建的源文件 發布:2025-05-15 18:54:08 瀏覽:611