I need to redirect my C program output to a text file with the command line. I need a command that automatically puts a C program output to a text file, and a command that takes the input to a C program from a text file. Can someone help please?
Asked
Active
Viewed 1,669 times
0
-
2look up "input redirection" and "output redirection", that is all you need to know. – Rorschach Nov 30 '16 at 13:39
-
1You should be using the redirection operators, `<` and `>`, to provide inputs and capture outputs, respectively. – Sourav Ghosh Nov 30 '16 at 13:40
-
2Possible duplicate of [Displaying Windows command prompt output and redirecting it to a file](http://stackoverflow.com/questions/796476/displaying-windows-command-prompt-output-and-redirecting-it-to-a-file) – Prajwal Nov 30 '16 at 13:41
-
This is not about programming. – too honest for this site Nov 30 '16 at 13:41
1 Answers
0
Basically, you need "input and output redirection".
Let's say you have a code that expects some output from user (you have fgets()
in your code - just an example), you want program to read from file, instead of waiting for user input on cmd...
you would call it: program.exe < input.txt
Similarly, for output, you want printf()
to write to file, instead of command prompt, you would do
program.exe > output.txt
To combine both in one line
program.exe < input.txt > output.txt

Rorschach
- 734
- 2
- 7
- 22