我想知道如何用 C 语言制作一个“持续运行”的 CLI 应用程序。我的意思是,例如,我只想打开终端并输入关键字,然后程序中的函数就会执行。就像“ls”是什么一样。当您键入 ls 时,它会列出当前目录的内容。同样,我想制作一个程序,在编译时,如果调用关键字,它会执行特定的内容。我不想使用 ./example 运行可执行文件,而是让命令始终可用。我使用的编译器是 gcc。我已读到需要创建目标文件,但我不知道如何使用它。
谢谢
I am building a CLI app that should do something similar to this:
./app
Welcome to the app, Type -h or --help to learn more.
./app -h
list of commands:...
Run Code Online (Sandbox Code Playgroud)
Here is the code i am trying to build:
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "Welcome to the app. Type -h or --help to learn more\n";
if(argv == "-h" || argv == "--help") {
cout << "List of commands:...";
}
return 0;
} …Run Code Online (Sandbox Code Playgroud)