Pretty sure your AudioFileClose() should not be inside the for-loop. That should go outside the loop, after you've written all the samples.
Please check against the downloadable code at the book's home page. I just downloaded and ran it, and it works as described in the book (although, since it was built for Lion, you will have to update the target SDK in the project settings if you're on Mountain Lion or Mavericks)
--Chris (invalidname)