1. What is the difference between end of a file and end of a string?
Ans: The feof() function indicates the end of any file that may be binary or text file. It is used as
indication to stop reading the characters from a character array and its ASCII value is 0. Whereas the
end of a string is used to terminate the string and it is indicated by NULL character and can be written as
'\0'. It is used as indication to stop reading the characters from file and its ASCII value is 0.
2. Distinguish between text mode and binary mode operations of a file.
Ans: Streams are categorized in to two types. They are text and binary.
Text file contains records or lines. Text or stream files compose characters. In text files, the end of
file is detected with feof() function. A special character whose ASCII value is 26 is inserted after the
last character of a file. As such a special character is absent in binary file.
Text files contain lines or records of text and each of its line has end of line marker at the end of line.
Whereas binary files are not broken into lines or records. Hence, end of line marker is absent while
writing in to binary files.
Binary files are a collection of bytes. Binary stream files would be used to read or write binary files
such as reading graphics files.
In text mode of operation, every character is treated takes one byte memory space for storage, so
when we want to store the numbers, e.g. 12345, it will take 5 bytes of memory.
To avoid this wastage of memory, binary files are used; in binary mode of operation, every value is
stored in its binary form, so it will require only two bytes of storage to store a number.
3. What is the use of fseek()? Explain its syntax.
Ans: The fseek() function is used to set the position of read or write pointer to some particular
byte location. The syntax of fseek() function is:
fseek(FILE *file_pointer, int offset, int position);
where offset indicates the number of bytes the pointer to be moved and position indicates the position
from which the offset is to be counted; it can be current position, beginning of the file or the end of file.
M14_ITL-ESL4791_02_SE_C14.indd 298 12/22/2012 5:06:42 PM