O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inside the Central Loop

Take a look at the central loop in main:

 ​ ​ ​ ​w​h​i​l​e​ ​(​!​f​e​o​f​(​s​t​d​i​n​)​)​ ​{​

Loop over the body of the while statement until the standard-in stream indicates that it has reached EOF (end of file). End of file happens when you explicitly type Control-D on a new line if you are typing text into the program. When in a pipeline, the standard-in stream will be closed when the program writing to it exits or otherwise closes the outgoing pipe on its end.

 ​ ​ ​ ​ ​ ​ ​ ​c​o​n​s​t​ ​s​i​z​e​_​t​ ​l​e​n​g​t​h​ ​=​ ​f​r​e​a​d​ ​(​b​u​f​f​e​r​,​ ​1​,​ ​B​U​F​F​E​R​_​S​I​Z​E​,​ ​s​t​d​i​n​)​;​

Read in no more than BUFFER_SIZE bytes. The fread() function is a record-oriented function that you'll see more of in

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required