Redirecting

How to redirect the contents of a file to a command?

The contents of the file are the arguments necessary for the command.

thx in advance.

bye
svh

This may be kind of cheating, but:

include <stdlib.h>

int main(int argc, char *argv[])
{
  return(system("./some-program `cat filename`"));
}

Or if you must do it from C alone, look into the execvp family of functions.

I will try it out

thx,
bye

well, above c program will do absolutely nothing.
if your shell script code is

./prog < file

then you can try this:

#include <stdio.h>

int main()
{
    int c;

    while( (c = fgetc(stdin)) != EOF )
    {
        /* do something with input char */
    }
}

Considering I actually wrote it and tested it before posting here, I think that pronouncement is premature. I'm presuming he means arguments when he says arguments, not stdin.

Or you can use Shell's "Here Documents" if you wanna put your command in the same place as your data on which that command will act.

$cat findpattern.sh
grep 'pattern' <<End # Here document tag
Hi here is pattern
Pattern here, but escape from grep
No grep in this line
Can't find here
Pattern here again
pattern here
End # Here document tag

$./findpattern.sh
Hi here is pattern
pattern here