Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
C programming power point presentation c ppt.pptx
1. K.S.R College of Engineering
Department of Computer Science and Engineering
c program
Topic : Random Access File
2. Definition
Random access file in C enables us to read or write
any data in our disk file without reading or writing
every piece of data before it. In a random-access file,
we may quickly search for data, edit it or even
remove it.
3. Function in random access file
There are three functions which help in using the
Random-Access file in C:
fseek()
ftell()
rewind()
4. Example program for ftell()
#include<stdio.h>
#niclude<lonio.h>
Void main()
{
FILE *fp;
Int length;
(lrscrc);
fp=fopen (“file.txt”,”r”);
fseek (fp,o,SEEK_END);
length = ftell (fp);
fclose (fp);
Printf (“size of file : %d bytes”, length);
getch ();
}
Output:
Size of file : 21 bytes.
5. Example program for fseek()
#include<stdio.h>
Void main () {
FILE *fp ;
fp=fopen (“myfile.txt”, “w+”);
fputs (“This is my subject”, fp);
fseek (fp,7,SEEK_SET);
fputs (“Programming in C”, fp);
fclose (fp);
}
OUTPUT :
Programming in C
6. Syntax of random access file
The general syntax to create a new file stream
for both read-write operations is given
below: RandomAccessFile raf = new
RandomAccessFile("myfile. dat", "rw"); Here,
“rw” is a mode string that has given as a
parameter to the constructor of
RandomAccessFile class.
7. Need for random access file
Random access files permit nonsequential, or
random, access to a file's contents. To access a
file randomly, you open the file, seek a
particular location, and read from or write to
that file. This functionality is possible with the
SeekableByteChannel interface.
8. Advantages
Random access files provide greater flexibility and
faster access to specific data points within the file.
They allow for the efficient processing of data that is
not ordered or arranged in a specific sequence.
Random access files provide greater flexibility and
faster access to specific data points within the file.