C Exercises: Delete a specific line from a file
8. Delete Specific Line from File
Write a program in C to delete a specific line from a file.
Assume that the content of the file test.txt is : test line 1 test line 2 test line 3 test line 4
Sample Solution:
C Code:
Sample Output:
Delete a specific line from a file : ----------------------------------------- Input the file name to be opened : test.txt Input the line you want to remove : 2 Now the content of the file test.txt are : test line 1 test line 3 test line 4
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to delete multiple specified lines from a file based on user input.
- Write a C program to remove lines that contain a specific keyword from a file.
- Write a C program to delete the first and last lines from a file and then display the updated content.
- Write a C program to remove every even-numbered line from a file using file I/O operations.
C Programming Code Editor:
Previous: Write a program in C to count number of words and characters in a file.
Next: Write a program in C to replace a specific line with another text in a file.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.