System函數的使用說明


#inlcude<stdlib.h>

int system(const char* command)

功能:在已經運行的程序中調用另一個外部程序

參數:外部可執行程序的名字

返回值:不同系統的返回值不一樣

 

實例程序

 

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

int main()
{
   printf("before sys\n");
  
   system("ls");
   //system("ls -alh");  

   //查看執行程序所在目錄下的所有目錄內容

    //Linux下(運行一個程序需要加./)

   // system("./hello"); 

   //windows(運行一個程序不需要加./)

   // system("hello");  // system("calc"); //計算器 

   //hello為該程序目錄下的可執行文件,程序會在執行到system的時候,調用hello這個程序
   


   printf("after sys\n");

  return 0;
}

結果

1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM