C Programming Language
  • Home
  • C Fundamentals
    • C Character Set
    • Tokens>
      • Keywords
      • Identifiers
      • Constants>
        • Definition and Its types
        • Numeric Constants>
          • Integer Constants
          • Real Constants
        • Character Constants
        • String Constants
        • Backslash Character
      • Operators>
        • Definition and Its types
        • Arithmetic
        • Relational
        • Logical
        • Increment
        • Decrement
        • Assignment
        • Arithmetic Assignment
        • Conditional
        • Bitwise
        • Special Operators
        • Hierarchy
    • Data Types>
      • Primary (Or) Basic
      • User-Defined
      • Derived
    • Variable>
      • Definition
      • Declaration
      • Initialization
  • Control Structures
    • Decision-Control>
      • If Statement>
        • Simple-if Statement
        • if-else Statement
        • Nested-if Statement
        • if-else ladder Statement
      • Switch Statement
    • Loop Control>
      • For
      • While
      • Do-While
  • Arrays
    • Introduction
    • Single-Dimensional>
      • Definition
      • Declaration
      • Initialization
    • Two-Dimensional>
      • Definition
      • Declaration
      • Initialization
    • Multi-Dimensional>
      • Definition
      • Declaration
      • Initialization
  • Functions
    • Definition
    • Standard Library Character Functions
    • Standard Library String Functions
    • Storage Classes>
      • Definition
      • Automatic
      • Register
      • Static
      • External
  • Pointers
  • Files
    • Concepts
    • Data Files and its Categories
    • Standard Files and its Categories
  • University Questions
    • April 2001 To 2005
    • April 2006 To 2010
    • April 2011 To 2015
    • November 2001 To 2005
    • November 2006 To 2010
    • November 2011 To 2015

File and its Usage
  • A file is a place on the disk.
  • A disk is a circular piece to the coating on an audio tape where a group of a related data is chargeable substance, similar to the coating on an audio tape where a group of a related data is stored permanently.
  • It is easier to access a file then reading data from a keyboard.
  • File handling in C is very simple, since it essentially treats a file as just a stream of characters and allows input and output in a file.
  • Structure of data in variables, arrays and structures are temporary; all such data are lost when the execution of the program ends. Many applications require that information to be read from or written on an auxiliary memory device. Such information is stored in the memory device in the form of a file.
  • Files are used for permanent storage of large amount of data. 
  • A file can be used to write or read data from a disk.

Why need to use files?

Often it is not enough to just display the data on the screen. This is because if the data is large, only a limited amount of it can be stored in memory and only a limited amount of it can be displayed on the screen. It would be inappropriate to store data this data in memory. Memory is volatile and its contents would be lost once the program is terminated. So if need the same data again it would have to be either entered through the keyboard again or would have to be regenerated pro-grammatically. Obviously both these operations would be tedious. At such times it becomes necessary to store the data in a manner that can be later retrieved and displayed either in part or in whole. This medium is usually a file on the disk.

How data is organized on the disk?

All data stored on the disk is in binary form. How this binary data is stored on the disk varies from on OS to another. However, this does not affect the C programmer, since the programmer has to use only the library functions written for the particular OS to be able to perform input/output. It is the compiler vendor’s responsibility to correctly implement these library functions by taking the help of OS.
                               |-----------------------------|                      |-----------------------------|                    |--------------------|              |--------------------|
                               |        Our Program      |------------- ->|  C Library Functions|-------------> |         OS            | -------->|       Disk           |
                               |-----------------------------|                      |---------------------------- |                    |--------------------|               |--------------------|

Powered by Create your own unique website with customizable templates.