C Programming + Tutorials in C for Beginners

C File Input/Output

Home  »  C Programming  »  C File Input/Ouput


     File is not the new concept. File is a more flexible approach than the previous data entry approach. Files are the mega data structure in information processing. Storage of information and its retrieval are the vital components of system design and information system. By using files data can be stored on the disks and can be read whenever you want without destroying the date. A file is place on the disk where a group of related data is stored permanently. By using files we can sense the data. Files establish a permanent links between inputs and ouputs as data can be stored and retrieved. A computer programmber or data entry operator always prefer to enter data in the files instead of storing the data temporary in the main memory using the direct keyboard facility.

Contents


Definition

     A file is a collection of related data structure pertaining to a single entity. A file having payroll data processes the information of pay elements and not about the personal and educational information of an employee. So we can say file has mainly two basic elements: information and a single entity.

Types of Files

     There are two mainly types of Files used in C Programming. These are below:




Files Operations

     The processing of files has number of operation according to the user's requirement and the problem definition. But some of the commonly used file operations are as follows:

  1. Naming a file
  2. Opening a file
  3. Reading data from a file
  4. Writing data to a file or creation of data file
  5. Closing a file
  6. Updating a file


Naming a File

     File name (data file name) should not be more than eight characters and three characters for extension. File name can be defined and enclosed by using the fopen() high-level I/O function. The general Syntax is as follows:

fopen("filename","mode");


For example, "Student.dat" is a data file name, which is defined and enclosed in the fopen() function as:
fopen("Student.dat","mode");



Opening a File

     A file is opened by using fopen() in build high-leve input/ouput function. The general Syntax is as follows:

FILE *fp;
fp = fopen("filename","mode");





Closing a File

     A file is Close by using fclose() in build high-leve input/ouput function. The general Syntax is as follows:

fclose(file-pointer);

For example
FILE *fl;
fl = fopen("Student","w");
fclose(fl);



Input/Ouput statements used in file handling

     File have different Input/Ouput statements used for different purpose. These are used to put data from variables to data file. The various Input/Ouput functions used with standard I/O are discussed as below:

  1. Character Input/Ouput (Standard I/O)
  2. String Input/Ouput (Standard I/O)
  3. Formatted Input/Ouput (Standard I/O)
  4. Record (Block) Input/Ouput (Standard I/O)


A Program Write data into File and Read data from File :







Write a Program How many Words in a File :






Copy One File to another File :







































Previous
Next Post »

2 comments

Click here for comments
suman
admin
25 August 2018 at 09:38 ×

thank you for sharing nice article
visit
web programming tutorial
welookups

Reply
avatar
Thanks for your comment