File Handling Questions.
File Handling Questions.
EXPT NO :
Aim
To write a C program that reads data from a text file and displays it on the screen.
Algorithm
1. Start
2. Declare necessary variables, including a file pointer.
3. Open the text file in read mode (r) using fopen().
o If the file cannot be opened, display an error message and exit.
4. Read the contents of the file using fgetc() or fgets() in a loop.
5. Display the content on the screen as it is read.
6. Close the file using fclose().
7. End.
Solution Code
Register No: RTC2024BCS021
Input:
input.txt file:
Output:
Result:
Register No: RTC2024BCS021
EXPT NO :
Aim
To write a C program that reads data from one text file and appends it to another file.
Algorithm
1. Start
2. Declare necessary variables, including two file pointers.
3. Open the source file in read mode (r) and the destination file in append mode (a).
4. If either file cannot be opened, display an error message and exit.
5. Read the contents of the source file using a loop and append the data to the
destination file.
6. Close both files using fclose().
7. End.
Solution Code
Register No: RTC2024BCS021
Input files:
1.Source file:
2.Destination file:
Output:
Result: