C语言所有的库函数调用,只能保证语法是一致的,但不能保证执行结果是一致的。
同样的库函数在不同操作系统下执行,结果可能不一样。
第一个程序,执行完,返回250#include <stdio.h>#include<stdlib.h>int main(){printf("before sys--------");system("./01_hello");printf("after sys---------");return 250;}------------------------------------------------------------------------------------------------------------------------------------------------在第二个程序中执行第一个程序,并输出第一个程序的返回值#include <stdio.h>#include <stdlib.h>int main(){int a=system("./02_system");//打印变量a的值printf("a=%d",a);}------------------------------------------------------------------------------------------------------------------------------------------------结果[root@localhost day03]# ./03_return before sys--------hello cafter sys---------//输出的是4864,不是250a=4864------------------------------------------------------------------------------
1、下载WinGW
2、安装WinGW,WinGW是一个安装器

3、运行WinGW,选择安装内容

安装

4、配置环境变量

5、查看是否安装成功

第一个程序#include <stdio.h>#include<stdlib.h>int main(){ printf("system---------");return 250;}第二个程序,执行第一个程序,并打印第一个程序返回的值#include <stdio.h>#include <stdlib.h>int main(){int a=system("system.exe");//打印变量a的值printf("a=%d",a);}编译和运行结果

编译产生的结果
