在C语言中,可以使用system()函数来调用系统命令。system()函数的原型如下:
int system(const char *command);参数command是要执行的命令字符串。system()函数会将command字符串传递给操作系统执行,并等待命令执行完毕后返回。返回值是命令的退出状态码。
以下是一个简单的示例,演示如何使用system()函数调用系统命令:
#include <stdio.h>#include <stdlib.h>int main() {int result = system("ls -l"); // 执行ls -l命令printf("命令执行完毕,退出状态码:%d\n", result);return 0;}在上述示例中,system()函数调用了ls -l命令,输出当前目录下的文件列表。执行完命令后,会打印命令的退出状态码。

