关闭。这个问题需要details or clarity .它目前不接受答案。
想改进这个问题?通过 editing this post 添加详细信息并澄清问题.
3年前关闭。
Improve this question
我想以这种方式将文件作为参数传递:
a.exe < testfile
我怎样才能得到
testfile
在我的 C 代码中?编辑
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char b[50];
gets(b);
puts(b);
//stuff
return 0;
}
我编译它,当我像这样通过 CL 运行它时
a.exe < testfile
我明白了
`
这是为什么?我在建议的解决方案中阅读了有关 stdin 的信息,但现在我被困在这里。
最佳答案
重定向 < testfile
将用文件 testfile
替换标准输入流.
只需像使用标准输入从键盘读取数据一样读取输入。
关于c - 在 C 中读取命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52128908/