Hi all - I'm new to this forum, though been around c programming for quite some while, now and then, again and again. Hope to enjoy your advices and give out some of mine, if I can.
Here's the problem: I'm writing a small piece of software, that uses the Huffman character encoding algorithm, to compress files. Everything else's worked out and the program itself is working, but - I'd need the program to do something like this. When the following is given in the command line:
>compress.exe < filename.txt > filename.cmp
where compress.exe is my program, filename.txt is the source file and filename.cmp is the destination file. The program should compresses filename.txt and write compressed data to filename.cmp. I know how to handle this:
but how can I check in the beginning, if the standard I/O streams HAVE indeed been redirected from and to a file. Because without this check, given for example, a following command:Code:int main(int argc, char *argv[]) { FILE *infile = stdin; FILE *outfile = stdout; compress(infile,outfile); ... return 0; }
>compress.exe
The program begins to wait for user keyboard input, to get data into the stdin stream. How could I avoid this, making sure that the stdin comes from an actual file instead of the keyboard ?