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

মডুলার C প্রোগ্রামিং (Modular C Programming)

কেবল মাত্র একটি ফাংশন দিয়ে কোনো বড়ো জটিল সমস্যা সমাধানের চেষ্টা করা ভাল প্রোগ্রামিংয়ের পদ্ধতি নয়। সঠিক পদ্ধতি হ'ল সমস্যাটিকে কয়েকটি ছোট ছোট এবং সরল টুকরো করে ফেলা যাতে তা আরও বিশদে বোঝা যায় । তারপরে এই ছোট এবং সরল সমস্যাগুলি সমাধান করার জন্য ছোট ছোট ফাংশন ব্লক তৈরি করা এবং পরে সেগুলি নিয়মানুযায়ী সংযোজিত করা ।

Programming Style

Programming Style

In this section, I'd like to briefly highlight some points that will help you write clean programs that can easily be read, understood, and maintained.

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 Is the C preprocessor part of the C compiler?

    A No. The C preprocessor is not part of the C compiler. With its own line-oriented grammar and syntax, the C preprocessor runs before the compiler in order to handle named constants, macros, and inclusion of files.

Compiling Your Code Under Conditions

Compiling Your Code Under Conditions

You can select portions of your C program that you want to compile by using a set of preprocessor directives. This is useful, especially when you're testing a piece of new code or debugging a portion of code.