2

I am trying to make a program that will read data in from a text file using input redirection, and then display a menu which will take input from the user using the keyboard. The issue is that stdin is set to read from the file and will not allow the user to use the keyboard. Does anyone know how to change the input source from the file to the keyboard in the code? I am using C

2
  • Do you redirect the input streams programatically, or is the program started with redirected streams? Commented Mar 6, 2014 at 14:54
  • The program is started with redirected streams i.e. ./a.out < input.txt. Also if I was to use freopen, which parameters would redirect the input to the keyboard? Commented Mar 6, 2014 at 19:31

1 Answer 1

2

Instead of redirecting stdin, you can open the text file using fopen and then read from it using fread.

And then read from stdin (the keyboard, in your case) like before.

Sign up to request clarification or add additional context in comments.

1 Comment

The requirement for the program is that the data is read using input redirection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.