當前位置:首頁 » 編程語言 » 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;
}
熱點內容
戰地5默認是什麼伺服器 發布:2025-09-18 17:59:32 瀏覽:296
安卓變ios系統主題怎麼弄 發布:2025-09-18 17:54:07 瀏覽:875
linux出口ip 發布:2025-09-18 17:51:57 瀏覽:936
androidbitmap使用 發布:2025-09-18 17:49:20 瀏覽:230
數字日期加密 發布:2025-09-18 17:43:46 瀏覽:495
網吧電腦顯示未連接上桌面伺服器 發布:2025-09-18 17:37:17 瀏覽:693
電腦壓縮文件怎麼解壓 發布:2025-09-18 17:27:59 瀏覽:383
資料庫數據類型表 發布:2025-09-18 17:11:56 瀏覽:27
java如何生產執行bat腳本 發布:2025-09-18 16:53:25 瀏覽:556
湖北的伺服器地址是多少 發布:2025-09-18 16:51:09 瀏覽:488