如何从 C 中的标准输入获取参数?

How can I get arguments from standard input in C?

我有一个要在 C 文件中执行的字符串,我想从标准输入中获取该字符串。

echo "Here is some random text.\n" | ./main.c

stdin like any other FILE 流中读取。

#include<stdio.h>

int main()
{
    char line[BUFSIZ];
    fgets(line, sizeof(line), stdin);
    printf("stdin: %s", line);
}