Reputation: 3137
If you're redirecting input for a compiled c program, what's the typical method of reading this input within the program. Is it simply scanf? Say you have a text file like the following:
1
2
3
4
With 4 numbers, one on each line. How do you redirect standard input in your program to read this file, and duplicate it to another text file? Is each new line sent through scanf?
Upvotes: 1
Views: 220
Reputation: 11394
If you are on Linux, redirection is very easy. If you executable name is a.out
$ echo `a.out` > file.txt
will redirect all output from a.out
to file.txt
Upvotes: 0
Reputation: 81349
Redirection of streams is an OS concept, it has nothing to do with the C language. If you read from stdin
, which is the standard input stream, you will deal with it correctly. Functions like scanf
use stdin
implicitly, so your program will work fine regardless of whether it gets its input from the console or from a redirected file.
Upvotes: 1