IT Help Desk > Programming Competition
Introduction to Programming Contest (File Input/Output)
(1/1)
Nazmul:
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:
--- Code: --- freopen("input.txt","r", stdin);
--- End code ---
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:
--- Code: --- freopen ("output.txt","w",stdout);
--- End code ---
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
--- Code: --- fclose(stdin);
fclose(stdout);
return 0;
}
--- End code ---
Now your program is ready to take input from file and produce output into file.
jas_fluidm:
thanks for the post
Navigation
[0] Message Index
Go to full version