|
-
October 28th, 2009, 09:10 PM
#1
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
-
October 29th, 2009, 01:47 AM
#2
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?
Before post, make an effort yourself, try googling or search here.
When posting, give a proper description of your problem, include code* and error messages.
*All code should include code tags
-
October 29th, 2009, 04:26 AM
#3
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().
-
October 29th, 2009, 05:04 AM
#4
Re: send file to program using following syntax "cat file.rle | ./code"
 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.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|