0% found this document useful (0 votes)
52 views4 pages

File Handling Exercises

The document outlines a series of programming tasks in C related to file handling, including creating, reading, counting words and characters, replacing lines, and appending lines to a text file. Each task includes test data and expected output to guide implementation. The example file used throughout is 'test.txt' with various content modifications demonstrated.

Uploaded by

johnmarbartolome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

File Handling Exercises

The document outlines a series of programming tasks in C related to file handling, including creating, reading, counting words and characters, replacing lines, and appending lines to a text file. Each task includes test data and expected output to guide implementation. The example file used throughout is 'test.txt' with various content modifications demonstrated.

Uploaded by

johnmarbartolome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Johnmar Bartolome L.

Magtira Assessment: File Handling

1. Write a program in C to create and store information in a text file.


Test Data
Input a sentence for the file: This is the content of the file test.txt.
Expected Output:
The file test.txt was created successfully...!!

2. Write a program in C to read an existing file.


Test Data:
Input the file name to be opened: test.txt
Expected Output:
The content of the file test.txt is:
This is the content of the file test.txt.

3. Write a program in C to count a number of words and characters in a file.


Test Data:
Input the file name to be opened: test.txt
Expected Output:
The content of the file test.txt are:
test line 1
test line 2
test line 3
test line 4
The number of words in the file test.txt are: 12
The number of characters in the file test.txt are: 36

4. Write a program in C to replace a specific line with another text in a file.


Assume that the content of the file test.txt is:
test line 1
test line 2
test line 3
test line 4
Test Data:
Input the file name to be opened: test.txt
Input the content of the new line: Yes, I am the new text instead of test line 2
Input the line number you want to replace: 2
Expected Output:
Replacement did successfully...!!
5. Write a program in C to append multiple lines at the end of a text file.
Assume that the content of the file test.txt is:
test line 1
test line 2
test line 3
test line 4
Test Data:
Input the file name to be opened: test.txt
Input the number of lines to be written: 3
The lines are:
test line 5
test line 6
test line 7
Expected Output:
The content of the file test.txt is:

test line 1
test line 2
test line 3
test line 4
test line 5
test line 6
test line 7

You might also like