Giving input form keyboard sometime become hazy during contest time. So, we use file i/o. Here i am going to give a sample code which takes inputs from file and produces output to file (text file)
Suppose we want to take input from the "input.txt" file and want to store the results in the "output.txt" file.
You will have to include one function call before taking first input:
freopen("input.txt","r", stdin); freopen function opens the "input.txt" data file in read mode "r" and sends it to standard input (stdin)
Place another freopen call for putting the outputs into file as below:
freopen ("output.txt","w",stdout);it opens the "output.txt" file into write mode "w" and acts as standard console output (stdout)
Important note: Never forgot to close these streams before end of the program
Now your program is ready to take input from file and produce output into file.