ICS Notes Computer Science Part 2 Chapter 14 File Handling in C Short Questions

ICS Notes Computer Science Part 2 Chapter 14 File Handling in C Short Questions 2nd Year Notes Online Taleem Ilm Hub

If you want to view other notes of ICS FA Computer Part 2 Please Click Here.



Q 1. What is data file?
Ans. A data file is a collection of related records. A records is a collection of fields. Any type of data can be stored in data files. Data in data files is stored permanently.

Q 2. What is stream?
Ans. The flow of data from one point to another is called a stream. The point from where data is sent is called source and the point where data is received is called destination.

Q 3. What are different types of streams?
Ans. There are different types of streams used for transfer of data. These are
  • Input stream
  • Output stream
  • Binary stream
  • Text stream


Q 4. What is text stream?
Ans. A flow of characters from a source to a destination is called text stream. In text stream characters are converted in to bytes. There is no one to one relation between the characters and the bytes. The number of characters and the number of bytes may not be same when characters are converted in to bytes. For example, a new line is stored as a carriage return and line feed pair.

Q 5. What is binary stream?
Ans. A flow of bytes from a source to a destination is called binary stream. No translation is required in binary stream. There is one to one correspondence between the bytes read or written and those on external device. Binary stream is used to transfer any types of data.

Q 6. What is input stream?
Ans. The flow of data from a source to a program is called input stream. For example C language program reads data from a data file. This flow of data from data file to C program will be input stream.

Q 7. What is output stream?
Ans. The flow of data from a program to a destination is called output stream. For example C language program write data to a data file. This flow of data from C program to data file is termed as output stream.

Q 8. What is pointer?
Ans. Variable are named memory locations used to store data. Different types of variable can store different types of data. Pointer is a special type of variable. It is not used to store data. It is used to store memory address used by another variable. Like variable, there are different types of pointers. The type of pointer should match the type of variable whose address it is holding.

Q 9. What is file pointer?
Ans. File pointer is a pointer type variable whose type is File. File is a special data type defined in stdio.h header file. When a file is opened it transfers from secondary storage to main memory. File pointer variable contain information about an opened file. Data files can be accessed with the help of File pointer. File pointer is used to read and write in a data file.

Q 10. What is meant by EOF?
Ans. Text files are stored on secondary storage. Different files have different size. A special end of file marker is used at the end of each text file. This marker is placed after the last character of text file. In C language is is denoted by EOF. EOF is used to detect the end of file.

Q 11. What is a string?
Ans. A collection of character enclosed in double quotations is called a string. The variable that is used to store a string is called string variable. C language does not provide any special data type to store string. As string is a combination of characters, a char array is used to store string.

Q 12. What is the purpose of fopen() function?
Ans. A file must be opened before use. We can read from or write into a file only if it is opened. Files are permanently stored on secondary storage. When a file is opened it's data is transferred in main memory. Header file stdio.h contain all standards file handling functions. fopen() function is used to open a file. A file pointer is attached with an open file.

Q 13. What is the purpose of fputs() function
Ans. fputs() function is used to write a string in text file. This function is defined in stdio.h header file before the use of this function the file must be open in write mode or append mode. The general syntax of this function is as follow

  • fputs( string, file pointer);


Q 14. What is the purpose of fgets() function
Ans. fgets() function is used to read a sting from a text file. This function is defined in stdio.h header file. Before the use of this function the file must be opened in read mode. The general syntax of this function is as follow:

  • fgets( str, n, file pointer);


Q 15. What is the purpose of putc() function
Ans. The putc() function is used to write a single character into text file at one time. Before the use of this function file should be opened is write or append mode. The syntax of this function is as follow:

  • putc( character, file pointer);


Q 16. What is the purpose of getc() function
Ans. getc() function is used to read a single character from a file. More than one characters can be read from a file by using this function repeatedly. Before the use of this function the file must be opened in read mode.

Q 17. What is the purpose of fprintf() function
Ans. The fprintf() function is used to write data in a file in specified format. Any type of data can be written in a file. The file must be opened in write or append mode before the use of this function. Its general syntax is as follow:

  • fprintf( fp, Format_string, argument);


Q 18. What is the purpose of fscanf() function
Ans. The fscanf() function is used to read data from a file in specific format. It works like scanf() function but scanf() function take data from keyboard. Its general syntax is as follow:

  • fscanf( fp, Control-string, Var);


Q 19. What is the purpose of fclose() function
Ans. When a file is open it is transferred from secondary storage to main memory. A connection is established between C program and file with the help of file pointer. When a file is closed its contents are transferred from main memory to secondary storage. Its connection with C program breaks. File pointer is destroyed and data of file becomes inaccessible. If a file is not closed properly some data may lose. The function fclose() is used to close a file opened by fopen() function.

Written by: Asad Hussain  &  Sana Hussain


2 Comments

Post a Comment

Previous Post Next Post