C প্রোগ্রামিং ও অ্যাডভান্স File অপারেশন

Submitted by tushar pramanick on Mon, 01/02/2012 - 16:39

In last hour's lesson you learned the basics of reading and writing disk data files. In this lesson you'll learn more about communication with disk data files. The main topics discussed in this hour are

    Random access to files
    Reading or writing binary data
    Redirecting the standard streams

In addition, the following C I/O functions are introduced in this lesson:

    The fseek(), ftell(), and rewind() functions
    The fscanf() and fprintf() functions
    The freopen() function




Summary

  •     The file position indicator can be reset by the fseek() function.
  •     The ftell() function can tell you the value of the current file position indicator.
  •     The rewind() function can set the file position indicator to the beginning of a file.
  •     After you specify the mode of the fopen() function for the binary file, you can use the fread() or fwrite() functions to perform I/O operations on binary data.
  •     Besides the fact that the fscanf() and fprintf() functions can do the same jobs as the scanf() and printf() functions, the fscanf() and fprintf() functions also allow the programmer to specify I/O streams.
  •     You can redirect the standard streams, such as stdin and stdout, to a disk file with the help of the freopen() function.

 

Related Items

The Basics of Disk File I/O

The Basics of Disk File I/O

Now let's focus on how to open and close a disk data file and how to interpret error messages returned by I/O functions.

Files Versus Streams

Files Versus Streams

Exercises : Answer the following Question

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Question and Answer

    Q What are the differences between a union and a structure?

Making Structures Flexible

Making Structures Flexible

The second application of unions is to nest a union inside a structure so that the structure can hold different types of values.