444 Programming and Data Structures
of line. In the same way ' t ' can be used to take the account of tabs. The text is also converted to
capital by using toupper () function and it is displayed.
b) f e of () The macro f eo f () is used for detecting the file pointer whether it is at the end of file or not.
It returns non-zero if the file pointer is at the end of file, otherwise it returns zero.
13.24 Write a program to detect the end of file using function feof(). Display the file pointer
position for detecting end of file.
# include <conio.h>
# include <stdio.h >
void main()
{
FILS *fp ;
char c;
fp -fo p e n ("t e x t.t x t" , mr " ) ;
c - f e o f ( f p ) ;
c l r s c r ( ) ;
printf ("File pointer at the beginning of the file : %dn",c);
while (Ifeofifp))
I
printf ("% c "^ );
C=getc(fp);
}
c=feof(fp);
printf ("File pointer at the end of file: %d ",c);
I
File pointer at the beginning of the file : 0
TECHNOCRATS LEAD THE WORLD
File pointer at the end of file : 32
Explanation At starting the f eof () function returns 0 (zero) because the file pointer is at the beginning
of file. After reading contents of file the file pointer reaches the end of file. At this stage the f e o f ()
function returns non-zero value with 32 in this program.
13.7 SEARCHING ERRORS IN READING/WRITING FILES
While performing read or write operations some times we do not get the result successfully. The
reason may be that the attempt of reading or writing the operation may not be correct. The provision
must be provided for searching the error while read/ write operations are carried out.
The 'C' language provides standard library function f e rr o r ( ) . This function is used for detecting
any error that might occur during read/write operation on a file. It returns a 'O' when the attempt is
successful otherwise non-zero in case of failure.