418 Programming and Data Structures
A) File Types
There are two types of files 1) Sequential file 2) Random accesses file.
1. Sequential File In this type datas are kept sequentially. If we want to read the last record of the
file we need to read all the records before that record. It takes more time. Or if we desire to access the
10th record then the first 9 records should be read sequentially for reaching to the 10th record.
2. Random Access File In this type data can be read and modified randomly. In this type if we
want to read the last records of the file, we can read it directly. It takes less time as compared to
sequential file.
13.3 STEPS FOR FILE OPERATIONS
There are three steps for file operation in C.
a) Opening of file.
b) Reading or writing file.
c) Closing file.
A C language supports many more file handling functions that are available in standard library.
These functions are listed in the table given below. All the functions that support C are not listed
here because all compilers do not support all the functions. One should check the C library before
using them.
Table 13.1 File functions
Function Operation
fopen()
Creates a new file for read/write operation.
fcloseO
Closes a file associated with file pointer.
closeall ()
Closes all opened files with f open ().
fgetcO
Reads the character from current pointer position and advances the pointer
to next character.
getc()
Same as fgetc ().
fp r in t f()
Writes all types of data values to the file.
f scanf ()
Reads all types of data values from a file.
putc()
Writes character one by one to a file.
fputc()
Same as putc ()
gets ()
Reads string from the file.
puts ()
Writes string to the file.
putw ()
Writes an integer to the file.
getw()
Reads an integer from the file.
freadO
Reads structured data written by fw rite () function.
fw rite ()
Writes block of structured data to the file.
f seek ()
Sets the pointer position anywhere in the file.
feof ()
Detects the end of file.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.133.160