Hey , suppose I made a simple factorial program in C , which takes a user input. I wish to give the input from a .txt file in which the number of which I want the factorial is written. How do do this simply using command prompt or anything. Please dont tell me to open the text file using fopen and f.gets functions.
int n=3, fact = 1,c;
printf("Enter a number to calculate it's factorial\n");
actually one way to give input to the program is by opening the .txt file in which my inputs are written by using fopen and such functions. I dont want to do that , what i want is that I run the program , and i write something on the console window which can link that .txt file automatically and then give me the output......
i heard somewhere that we use such a thing --
That is redirecting the standard input. In this case, the "<" symbol tells the program to take its stdin input from the file input_filename.txt instead of from the keyboard.
It doesn't require any changes to the program itself, it is simply using the operating system capabilities to alter the behaviour.
Thank you but sir please can you show me how to do this. I just heard such a thing from somewhere. When I run the code that i have provided and write in the console window $factorial.exe<input.txt
then nothing happens but the program just returns me the factorial of number 3 whereas in m input.txt file I have written the number 4.
Please demonstrate it how to use the four written in the input.txt file as an input to my program using $program_name.exe<input_filename.txt
I have made that factorial program on DEV C++ and I use windows. Please tell me whether I should modify my code. Also when I click on COMPILE AND RUN button , a console window opens . Do i need to write $factorial.exe<input.txt in this window when it seeks me for an input ?
let us say my program is saved as factorial.c
and the input file is input.txt
I am making a programming assingment on an online judge