Search code examples
cheaderheader-filesreadfilerecords

Reading the header of a file


I have searched all over the internet looking for an answer to my own question, but I can't seem to find one that I can understand. With that being said, it is a multi-part question so bear with me.

  1. What is a header file in C?

  2. What does it mean to read the header for the file so you know the number of things to process?

  3. Does getting volume information have anything to do with reading the header of a the file?

Thanks guys!


Solution

    1. You write a C program to do some kind of task. For example, your C program might query the OS for volume information, and report back the results in a command prompt.

    2. "Writing a program" involves:

      a) defining the task (EXAMPLE: get volume information).

      b) Writing the code.

      c) Compiling the code into an executable program

      d) Running the program to accomplish the task.

    3. Almost every C or C++ program you write will have one or more "header" files.

      A header effectively defines an "interface", usually to functionality provided by one or another "library".

      For example, header "stdio.h" is needed to use functions like "printf()" or "fopen()".

    4. You "#include" the header when you write your code (b); then the compiler reads the header when it compiles the program (c).

      The header is only important in steps b) and c).

      The only thing you do is "#include" the header in your source code.

      The compiler does the rest.

    5. You can read more about headers here:

    http://www.tutorialspoint.com/cprogramming/c_header_files.htm