I have an assignment where I have to redirect input from a file through stdin when the program starts.
its executed like this:
./program < textfile
The question is, I want to be able see if theres data in stdin when the program starts, otherwise when I try to process the data from stdin it just hangs until the user presses ctrl+d (on SunOS).
Code I'm using:
Code:#include <stdio.h>
int main(int argc, char **argv)
{
/* redirect input from the console to stdin */
char *buf;
while (fgets(buf, 1024, stdin)!=NULL)
{
printf("%s", buf);
}
free(buf);
return 0;
}
So far I've tried to use feof() with no luck.
Thanks in advance for any input.