unit 5 qp
unit 5 qp
FILE PROCESSING
Files Types of file processing: Sequential access, Random access Sequential access file - Random access
UNIT-V / PART-A
1. What is a File?
A File is a collection of related information that is permanently stored on the disk and
allows us to access and alter the information whenever necessary.
2. How do you open a file?
The File is opened by the statement
- means file pointer, mode is the
file opening mode such as write, read, or append mode.
3. How do you close a file?
The file is closed by the statement fclose(file-pointer);
4. Mention any five file functions. (Jan 14)
fopen() :Creates a new file for use Opens a new existing file for use
fclose() : Closes a file which has been opened for use
fprintf() : Writes a set of data values to a file
fscanf() : Reads a set of data values from a file
fseek() : Sets the position to a desired point in the file
ftell() : Gives the current position in the file
rewind() : Sets the position to the beginning of the file.
5. What is the use of rewind () function?
This function is used to reset the pointer to the beginning of the file.
6. What do you mean by Command line arguments? (or) What does argv and argc
indicate in command-line argument? (May 18,19)
The main functions can have arguments passed which are called as command line
arguments. There are two command line arguments:Argument count denoted by argc
and Argument vector denoted by argv
The argc is an integer variable which denotes the number of parameters passed and argv
is pointer to array of character strings. The syntax is as follows:
main( int argc , char * argv[ ])
{
}
It can also be returned as
main(argc,argv)
int argc;
char * argv[];
{
}
7. What is sequential access file?
To reading or writing data records in sequential order, that is, one record after the other.
To read record 10, for example, you would first need to read records 1 through 9.
8. What is Random access file?
To the ability to access data at random. The opposite of random access is sequential access.
To go from point A to point Z in a sequential-access system, you must pass through all
intervening points. In a random-access system, you can jump directly to point Z.
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
UNIT-V / PART-B
1. Write a program that will receive a filename and a line of text as command line
arguments and write the text to the file.
2. Write a program to copy the contents of one file into another.
3. Write a program that appends one file at the end of another.
4. Write a program that compares 2 files and returns 0 if they are equal and 1 if they are
not.
5. Explain in detail various functions for sequential file manipulations and operations.
6. Write a complete C program for reading an employee file containing { emp no,name,
salary, address}. Create an output file containing the name of those employees along
with their salary and address. (Jan 14)
7. a) Write the C program to find the number of lines in a file.
b) Write the C program to print contents in reverse order of a file.
8. Write the C program to compare contents of two files.
9. Explain the types of file processing with necessary examples. (May 18)
10. Write the C coding for finding the average of number stored in sequential access file.
(May 18)
11. Write the case study of sequential Access file is differing from Random Access
(May 18)
12. Write a C program to write all the members of an structures to a file fwrite( ). Read the
array from the file and display on the screen. (May 18)
13. Explain in detail various operations that can be done on the file giving suitable
examples. (May 19)
14. Explain in detail random access in files along with the functions used for the same in C.
Give suitable examples. (May 19)
CS3251_PIC