我想编写一个 C 代码来在 unix 中压缩文件。我使用 UNIX shell 命令“zip -r filepath”使用系统函数实现了它。当我直接通过 UNIX shell 执行 zip -r filepath 命令时,该命令有效。
我已经编写了如下代码
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int system(const char *zip -r /root/Desktop/hi.txt);
return 0;
}
但是我收到编译时错误
"error:expected ‘;’, ‘,’ or ‘)’ before string constant"
syntax system function : http://linux.die.net/man/3/system
int system(const char *command);
我该如何解决这个问题?我尝试将 UNIX 命令放在引号中,尽管它不起作用。
最佳答案
这不是在 C 中调用函数的方式。尝试:
system("zip -r /root/Desktop/hi.txt");
关于c - 如何通过 UNIX 命令行以编程方式压缩文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9443124/