Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read file into a command line?

Basically what I want to do is have a program with int main(argc, *argv[]) and instead of writing chars into command line, I want to have my program read those words from a file. How could I accomplish this? Is there a special command in Linux for that?

like image 370
deviance Avatar asked Feb 10 '26 23:02

deviance


1 Answers

You can use standard redirect operations in a *nix shell to pass files as input:

./myprogram < inputfile.txt

This statement executes your program (myprogram) and pumps the data inside of inputfile.txt to your program

You can also redirect the output of program to a file in a similar fashion:

./myprogram > outputfile.txt
like image 174
Hunter McMillen Avatar answered Feb 13 '26 15:02

Hunter McMillen