Given a file and a line number n, the task is to delete nth line from the given text file.
Suppose the initial content of myfile.txt is :
GeeksforGeeks GeeksforGeeks IDE GeeksforGeeks Practice GeeksforGeeks Contribute
After Deletion of Line 2 the content would be :
GeeksforGeeks GeeksforGeeks IDE GeeksforGeeks Contribute
1) Open the source file in input mode and read it character by character.
2) Open another file in output mode and place contents in the file character by character.
3) Rename the other file to the source file.
Note: Run this code offline IDE keep text file name as "a.txt" in same folder
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Equation of straight line passing through a given point which bisects it into two equal line segments
- C program to delete a file
- C++program to delete the content of a Binary File
- Number of ordered points pair satisfying line equation
- Program to delete Nth digit of a Number
- Line Splicing in C/C++
- Draw a line in C++ graphics
- Command line arguments in C/C++
- Command line arguments example in C
- How to create a command-line progress bar in C/C++
- Swap two variables in one line in C/C++, Python, PHP and Java
- Shortest distance between a Line and a Point in a 3-D plane
- C Program to count number of lines in a file
- C program to copy contents of one file to another file
- Color all boxes in line such that every M consecutive boxes are unique
- C++ program to create a file
- C Program to print contents of file
- C Program to find size of a File
- C++ program to append content of one text file to another
- C++ program to modify the content of a Binary File
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.