I want to pass a file into a c program.
If I am doing it in the IDE this arguments
./test string string < test.txt
return arg
Redirection is performed by the shell, and is not (directly) visible to your program.
./test string string < test.txt
means,
test.txt
for reading on file descriptor 1./test
with the arguments string
and string
The program run in point 2 will inherit the parent's file descriptors, so its standard input will be connected to the opened file handle (rather than the shell's current standard input, which could be your terminal, or a different file handle).
As an aside, you probably want to avoid calling your programs test
, though as long as you don't forget to invoke it with an explicit path, this is harmless.