Hello everybody.
I need help with input redirection. I'm using it to read in a file full of
integer values which I'm putting into array. After sorting it , I'm prompting
a user to enter a value to search for in the array but my program skips
the scanf command. My guess this happens because this input redirection
thingy turns on once I typed in '<' at the prompt and it remains on the whole time.
If it is in fact so, how do I turn it off?
Dang!
My Proff wants me to read in a file using input redirection,
put the values in the array, copy it, sort one of the copies and than use
linear and binary searches on both copies of the array and print out the
position and number of comparisons it took to find a value in all four cases.
The value to search for should too be obtained from user using standard input.
You should contact your professor - maybe there is a misunderstanding? It is not possible to change the standard input while the program is running. Once a program starts, whatever it is inputting from is what it will always be inputting from.
You can, however, pass the number to search for as an argument:
myprogram.exe 42 < input.txt
1 2 3 4
int main(int num_arguments, charconst *const *arguments)
{
//Note: the first argument (argument 0) is always the name of your program file
}
EDIT: If you close the file, that's closing the standard input stream. AKA, no more input, ever.