Sams Teach Yourself C in 21 Days

(singke) #1
Using Disk Files 473

16


Q How many files can I open at once?
AThis question can’t be answered with a simple number. The limitation on the num-
ber of files that can be opened is based on variables set within your operating sys-
tem. On DOS systems, an environment variable called FILESdetermines the
number of files that can be opened (this variable also includes programs that are
running). Consult your operating system manuals for more information.
Q Can I read a file sequentially with random-access functions?
AWhen reading a file sequentially, there is no need to use such functions as fseek().
Because the file pointer is left at the last position it occupied, it is always where
you want it for sequential reads. You can use fseek()to read a file sequentially;
however, you gain nothing.

Workshop ............................................................................................................


The Workshop provides quiz questions to help you solidify your understanding of the
material covered and exercises to provide you with experience in using what you’ve
learned.

Quiz ..............................................................................................................


  1. What’s the difference between a text-mode stream and a binary-mode stream?

  2. What must your program do before it can access a disk file?

  3. When you open a file with fopen(), what information must you specify, and what
    does this function return?

  4. What are the three general methods of file access?

  5. What are the two general methods of reading a file’s information?

  6. What is the value of EOF?

  7. When is EOFused?

  8. How do you detect the end of a file in text and binary modes?

  9. What is the file position indicator, and how can you modify it?

  10. When a file is first opened, where does the file position indicator point to? (If
    you’re unsure, see Listing 16.5.)


Exercises ........................................................................................................


  1. Write code to close all file streams.

  2. Show two different ways to reset the file position pointer to the beginning of the
    file.


26 448201x-CH16 8/13/02 11:13 AM Page 473

Free download pdf