send file to program using following syntax "cat file.rle | ./code"
Does anyone know how I would set up my program to allow a text file to be piped into my compiled code?
it should work by issuing a command similar to the one below
cat file.rle | ./code
thanks :)
Re: send file to program using following syntax "cat file.rle | ./code"
Sorry, this does not make any sense to me. Please explain with a bit more detail. What do you hope to accomplish?
Re: send file to program using following syntax "cat file.rle | ./code"
Use stdin in your program to get the data passed to the pipe.
Code:
c = (char) fgetc(stdin);
printf("%c", c);
stdin is a keyword recognized by your C compiler.
Use fgetc() or fread(). Don't use fopen() and fclose().
Re: send file to program using following syntax "cat file.rle | ./code"
Quote:
Originally Posted by
dustout
it should work by issuing a command similar to the one below
cat file.rle | ./code
Your program just needs to read from standard input. The shell command sends the content of the file as input for your program.
Thus the following program:
Code:
#include <iostream>
#include <string>
int main() {
std::string word;
std::cin >> word;
std::cout << "Input starts with the word " << word << "\n";
}
will print the first word of the file.rle that you pipe to it.