Write Python code to perform the following:
(i) Copy content of file first.txt to second.txt
(ii) Reading a file
(iii) Writing into a file
(iv) Appending into a file
(i) Copy content of file first.txt to second.txt in Python:
```python
with open('first.txt', 'r') as file1:
content = file1.read()
with open('second.txt', 'w') as file2:
file2.write(content)
```
(ii) Reading a file in Python:
```python
with open('filename.txt', 'r') as file:
data = file.read()
print(data)
```
(iii) Writing into a file in Python:
```python
with open('filename.txt', 'w') as file:
file.write("This is the new content.")
```
(iv) Appending into a file in Python:
```python
with open('filename.txt', 'a') as file:
file.write("\nThis line is appended.")
```
---
In C language:
(i) Copy content of file first.txt to second.txt:
```c
#include <stdio.h>
int main() {
FILE *file1 = fopen("first.txt", "r");
FILE *file2 = fopen("second.txt", "w");
char ch;
if (file1 == NULL || file2 == NULL) {
printf("Error opening files.\n");
________ _____ ____ _________ ___ ___ ___.
_______ ____ _________ __________ ________ ______ ________ ________.
________ ___ _________ ____ ________ ______ ____ __________ ____ __________.
____ ____ ___ ______ ___ ________ _______ _________ ________ ______.
__________ ___ ______ ____ ____ ____ _________ ________ ________.
____ _______ _____ ___ _______ _________ __________ __________ __________ _______ __________ _________.
________ _____ _____ ______ ___ ___ __________ _________.
_______ ______ ____ _____ _________ ___ ________ ___ _______.
_________ _______ __________ ______ _________ ______ _______ __________ _______ __________ _________ _________.
____ ________ ____ ____ _____ _______ __________ ____.
_______ ___ ____ ____ ________.
_______ ____ __________ _____ __________.
_______ _________ ________ _________ ______ _________ ________ ____ ________ _____ _______ _________.
_________ _______ ______ _____ ________ __________ ____ _____ _________ ________.
_____ ____ _____ _________ ________ ________ ___ ________ ___ _____ ______.
_______ _________ _____ __________ _____ _________ _________ _____.
__________ _____ ________ ___ ___ ____ _______ ___ ___ _______ ________.
__________ __________ __________ _______ _____ _________ _________ ________ _____ ________ ______ ________.
____ __________ _________ _____ _______ ___ _________ ___.
_____ _________ _______ __________ _________ ________ ____ ________ ___.
______ _____ ____ _____ ________.
_____ ___ ___ ___ ________ ____ ___ ______.
____ _____ _____ _______ ________ __________.
________ _______ _________ ____ ________ ______.
______ ______ ___ ________ _________ ___ __________ ______ ________.
_________ ______ _________ _________ ___ _________ _________ _______ _________ _________.
_____ _____ __________ ___ ________.
_____ _______ ____ _________ __________ _________ _____ ___ __________.
_____ ___ ___ ________ ____ _______ ______.
_______ _________ _____ ________ __________ _______ __________ _____ ___.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required