C-Programming

File handling

We all know that many information are required to be written or read from an auxiliary memory device .These type of information is stored on the memory device in the form of a data file. Thus, data file allows us to store information permanently, and to access and alter that information at the time of necessity. If there were no such data files there would be no provision for storing, editing and retrieving such information. Thus for the same purpose in C language, an extensive set of library functions are available for creating and processing these files. There are mainly two major categories of data files and they are as follows:

  1. Stream – Oriented (or standard) data files
  2. System – Oriented (or low-level) data flies

The System- oriented data files are divided into two categories they are

  1. i) Text Files:
  • consists of consecutive characters
  • These characters can be interpreted as individual data items, or as components of strings or numbers.

Ii) Unformatted data files:

  • organizes data into blocks containing contiguous bytes of information
  • These blocks represent more complex data structure, such as array and structures.

System- oriented data files:

  • are more closely related to the computer’s operating system
  • more complicated to work with
  • A separate set of procedures, library functions are required to process these files

Here our study will be mainly focused only on Stream- oriented data files.

The C file system is composed of several interrelated functions. The most common of these are shown below. They require the header fie stdio.h to be included.

Name                     Function

fopen( )                          opens a file

fclose( )                          closes a file

putc( )                            write a character to a file

fputc( )                           same as putc( )

getc( )                             reads a character from file

fgetc( )                            same as getc( )

fgets( )                            reads a string from a file

fputs( )                           writes a string from file

fseek( )                           seeks to a specified byte in a file

ftell( )                             returns the current file position

fprintf( )                         is to a file what printf() is to console

fscanf( )                          is to a file what scanf() is to console

feof( )                             return true if end-of- file is reached

ferror( )                          return true if an error has occurred

rewind( )                        resets the file position indicator to the beginning

remove()                        erases a file

fflush( )                          flushes a file

Some important Questions from Structure (Prev Lesson)
(Next Lesson) The FILE Pointer
Back to C-Programming

No Comments

Post a Reply

Teacher
Bhim Gautam
Role : Lecturer
Read More
error: Content is protected !!