How do I check if my program has data piped into it.

Posted by monkeyking on Stack Overflow See other posts from Stack Overflow or by monkeyking
Published on 2010-04-02T00:49:30Z Indexed on 2010/04/02 0:53 UTC
Read the original article Hit count: 304

Filed under:
|
|
|

Im writing a program that should read input via stdin, so I have the following contruct.

FILE *fp=stdin;

But this just hangs if the user hasn't piped anything into the program, how can I check if the user is actually piping data into my program like

gunzip -c file.gz |./a.out #should work
./a.out  #should exit program with nice msg.

thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about c