Random access file
Random Access
Data can be read and modified
randomly.
If we want to read the last record we
can read it directly.
It takes less time when compared to
sequential file.
The following functions are used for random
access file processing.
fseek()
ftell()
rewind()
fseek()
It is used for seeking the pointer
position in the file at the specified byte.
SYNTAX:
fseek(file pointer, displacement,
pointer position);
[SEEK_SET,SEEK_CUR,SEEK_END]
ftell()
The function returns the value of the current
pointer position.
The value is count from the beginning of the
file.
SYNTAX:
ftell(fptr);
rewind(fptr)
The function is used to move the file
pointer to the beginning of the given
file.
SYNTAX:
rewind(fptr);
Example Program
EXPLORING FILE OPERATIONS
Output:
File size:27 bytes
Contents of the file:
Hello, this is a test file.