System函数的使用说明

#inlcude<stdlib.h>

int system(const char* command)

功能:在已经运行的程序中调用另一个外部程序

参数:外部可执行程序的名字

返回值:不同系统的返回值不一样

实例程序

 

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

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

   //查看执行程序所在目录下的所有目录内容

    //Linux下(运行一个程序需要加./)

   // system("./hello"); 

   //windows(运行一个程序不需要加./)

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

   //hello为该程序目录下的可执行文件,程序会在执行到system的时候,调用hello这个程序
   


   printf("after sys ");

  return 0;
}

结果

1

原文地址:https://www.cnblogs.com/wenshinlee/p/11002694.html