C 系统函数在其他字符串之前获取

标签 c system

我正在尝试编写一个简单的 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/

相关文章:

c - 结构中的位是否有保证

c++ - gp_camera_file_get 是如何工作的?

python - OSX 使用 os.system 运行 Scrapy 脚本

c - Linux 中的 atomic_t

windows - 在 system() 函数中使用变量 c++

c++ - 毕业设计

c - 行主矩阵乘法与列主矩阵乘法

c - 如何知道文件描述符是否被打开?

c - C语言中如何将函数结果保存到文本文件中

java - 使用 java 写入 Mac 和 Windows 文件