Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StdIn problem

Status
Not open for further replies.

makaveliuk

Programmer
Dec 1, 2003
46
GB
How do you look for an EOF on the Stdin?

I am reading data from Redmon on the Stdin to write to a file but it keeps ending input early, I am using a loop:

while( bResult && nBytesRead > 0 )
{
bResult = ReadFile(hStdIn, &inBuffer, 81920, &nBytesRead, NULL);
}

Any ideas?
 
stdin is not a regular file, so use scanf function to read it.

Ion Filipski
1c.bmp
 
Could you give me an example?

I have tried it but it is worse than the ReadFile() method.

I am reading print output from Redmon and placing it in a temporary file with the loop.

Thanks.
 
Code:
char buff[BUFSIZ];
while ( fgets( buff, sizeof buff, stdin ) != NULL ) {
  // do stuff
}
This loop will read stdin until EOF or error
Use feof() and ferror() to find out which


--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top