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