C - 运行 带有参数的程序,例如 ./prog -p 8888

C - Run program with parameters such as ./prog -p 8888

所以我在 C 中进行服务器和客户端之间的通信。我在网上搜索它时遇到问题如何执行以下操作。

./server -p 1234
./client -p 1234 -h asdffdsasdf

有人可以描述一下在项目中做这件事的基础知识吗?或者它是否包含在 Makefile 中?(使用 Putty 终端)。

或者告诉我一个解释得很好的网站,因为我不知道该 google 做什么。

非常感谢!

您需要使用程序启动参数;参见 Standard 5.1.2.2.1

例如

#include <string.h>
int main(int argc, char **argv) {
    if (argc >= 2) {
        if (strcmp(argv[1], "-p") == 0) /* -p detected */;
    }
    return 0;
}

TLDR:请阅读标题