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 #define and #undef Directives

The #define and #undef Directives

The #define directive is the most common preprocessor directive, which tells the preprocessor to replace every occurrence of a particular character string (that is, a macro name) with a specified value (that is, a macro body).

The C Preprocessor Versus the Compiler

The C Preprocessor Versus the Compiler

One important thing you need to remember is that the C preprocessor is not part of the C compiler.

What Is the C Preprocessor?

If there is a constant appearing in several places in your program, it's a good idea to associate a symbolic name to the constant, and then use the symbolic name to replace the constant throughout the program. There are two advantages to doing so. First, your program will be more readable.

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 Why is random access to a disk file necessary?