Files 419
ferrorO
Reports error occurred while read/write operations.
perrorO
Prints compilers error messages along with user defined messages.
fte llO Returns the current pointer position.
rewind ()
Sets the record pointer at the beginning of the file.
unlink ()
Removes the specified, file from the disk.
rename ()
Changes the name of the file.
a. Opening o f file A file has to be opened before beginning of read and write operations. Opening
of file creates a link between the operating system and the file functions. We have to specify the
name of file and it's mode to the operating system. This important task is carried out by the structure
FILE that is defined in s t d i o . h header file. So this file must be included.
When a request is made to the operating system for opening a file, it does so by granting the
request. If request is granted the operating systems points to the structure FILE. In case the request
is not granted it returns NULL. That is why the following declaration before opening of the file is to
be made.
FILE * fp
Where, fp is file pointer.
Each file that we open has its own FILE structure. The information that the file contains may be its
current size, its location in memory etc.
The only one function to open a file is f open ().
Syntax for opening the file
FILE * fp ;
fp=fopen (M a ta , t x t " , " r " ) ;
Here, f p is a pointer variable that contains address of the structure FILE that has been defined in the
header file " s t d i o . h". The function fopen () will open a file "d a ta . tx t " in read mode. The
C compiler reads the contents of the file because it finds the read mode ( " r * ). Here, *r* is a string
and not a character. Hence, it is enclosed with double quotes and not with single quotes.
The f open () performs three important tasks
1. It searches the disk for opening the file.
2. In case the file exists, it loads the file from the disk into memory. If the file is found with huge
contents then it loads the file part by part.
3. If the file is not existing this function returns a NULL. NULL is a macro defined character in the
header file "s t d io .h ". This indicates that it is unable to open file. There may be following
reasons for failure of f open () functions. A) When the file is in protected or hidden mode. B)
The file may be used by another program.
4. It locates a character pointer, which points the first character of the file. Whenever a file is opened
the character pointer points to the first character of the file.
Given below are different modes in which a file can be opened.
A. Text Modes
1. w (w r ite ) This mode opens a new file on the disk for writing. If the file already exists, it will be
overwritten without confirmation.
..................Content has been hidden....................

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