Unit 6: File Handling - Subjective Questions

CAP1008 — C Programming • Practice Questions with Detailed Answers

20 questions

1

Define a file in the context of C programming. Explain why file handling is important in real-world applications.

2

Describe the different categories of files used in C programming.

3

Distinguish between text files and binary files in C with suitable examples.

4

Explain the process of opening a file in C using the fopen() function. Describe its syntax and return value.

5

List and explain the various file opening modes available in C.

6

Explain the importance of closing a file in C. Describe the fclose() function with syntax and example.

7

Describe the character input/output functions getc()/fgetc() and putc()/fputc() with examples.

8

Explain the string handling functions fgets() and fputs() used in file operations with syntax and examples.

9

Explain the formatted I/O functions fprintf() and fscanf() with syntax and a suitable example program.

10

Explain the block I/O functions fread() and fwrite() used for reading and writing binary files. Illustrate with an example.

11

Compare sequential file access and random file access in C. Explain the role of fseek(), ftell(), and rewind().

12

Write a C program to read the contents of a text file and display it on the screen. Explain the logic used.

13

Explain the concept of the End-of-File (EOF) marker and the feof() function in C file handling.

14

Write a C program to copy the contents of one file into another file. Explain each step.

15

What is a file pointer in C? Explain the role of the FILE structure in file handling.

16

Explain how to perform reading and writing of structures into a binary file in C with a complete example program.

17

Describe the complete file handling process in C, from opening to closing a file, covering all essential steps. Support your answer with a general program structure.

18

Distinguish between the file functions fprintf()/fscanf() and fwrite()/fread(). When should each pair be used?

19

Explain error handling in file operations in C. Discuss the use of ferror(), perror(), and checking return values.

20

Write a C program to count the number of characters, words, and lines in a text file. Explain the logic.