我正在尝试编写一个简单的 C 程序来打印 C 编译器版本。所以我写道:
#include <stdio.h>
int main() {
printf("you have %d", system("gcc --version");
}
输出:
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
you have compiler 0
有什么想法吗?
最佳答案
system
执行 shell 命令并返回命令的状态。在您的情况下,值为 0 意味着命令已成功运行。
关于C 系统函数在其他字符串之前获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36233842/