[英]How can I get input via file without opening and closing the file in C?
I want to get input from a file in C without opening and closing it, like with use of fscanf
or fgets
. 我想从C中的文件中获取输入而不打开和关闭它,就像使用
fscanf
或fgets
。 I just want to redirect my stdin to a file. 我只是想将我的stdin重定向到一个文件。
You can always use redirection from the command line: 您始终可以从命令行使用重定向:
yourprogram < input_file
Use scanf as you normally would for keyboard input. 像往常一样使用scanf进行键盘输入。 Redirection is nice because you can get input from a file or the keyboard with the same program (if you don't use redirection, input will come from the keyboard).
重定向很好,因为您可以使用相同的程序从文件或键盘获取输入(如果您不使用重定向,输入将来自键盘)。
Also, you can redirect output to a file: 此外,您可以将输出重定向到文件:
yourprogram > output_file
Or both: 或两者:
yourprogram < input_file > output_file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.