C重定向导致scanf不接受输入
出于某种原因,在使用c重定向将输入传递给stdin后,scanf无法正常工作。 我在没有c重定向的情况下测试了相同的代码,它工作得非常好 另外,在使用fflush(stdin)执行scanf操作之前,我尝试过刷新stdin,但也没有成功 像这样运行我的可执行文件C重定向导致scanf不接受输入,c,gcc,clang,scanf,C,Gcc,Clang,Scanf,出于某种原因,在使用c重定向将输入传递给stdin后,scanf无法正常工作。 我在没有c重定向的情况下测试了相同的代码,它工作得非常好 另外,在使用fflush(stdin)执行scanf操作之前,我尝试过刷新stdin,但也没有成功 像这样运行我的可执行文件 ./3240Assignment0 < test-input.txt 问题是航站楼没有给我进入的机会 任何信息或输入 我的终端脚本 Joes-MacBook-Pro:a0 joemanto$ make test ./3240As
./3240Assignment0 < test-input.txt
问题是航站楼没有给我进入的机会
任何信息或输入
我的终端脚本
Joes-MacBook-Pro:a0 joemanto$ make test
./3240Assignment0 < test-input.txt
Tell me something nice:
Thank you for your message!
Joes-MacBook-Pro:a0 joemanto$
Joes MacBook Pro:a0 joemanto$make测试
./3240Assignment0
它接受输入,它只接受您告诉它接受输入的文件的输入
STDIN有三个选项:
:交互式输入作业
:从文件中获取输入assignment
:从commandcommand |赋值
(管道)的结果中获取输入command
因为您使用的是第二种形式,所以不能同时接受交互式输入。它只有一个输入源。为什么希望程序从终端读取?您已从文件中显式重定向stdin,因此
scanf
从文件中读取。
Joes-MacBook-Pro:a0 joemanto$ make test
./3240Assignment0 < test-input.txt
Tell me something nice:
Thank you for your message!
Joes-MacBook-Pro:a0 joemanto$