C programming delete a line in a file




















Okay so now your answer does little other than re-iterate what the OP's code is doing, then deny that there is a question. Not useful. I think someone just mass down voted everyone's answer. Still; what I said is a simplified version of what's used by databases Sarmad Ali Sarmad Ali 1 1 silver badge 12 12 bronze badges. Why is it necessary to buffer the entire file contents? That is very inefficient and I don't see how it will solve the problem. Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Visit chat. Linked 0. Related Hot Network Questions.

Question feed. Stack Overflow works best with JavaScript enabled. Copy paste the whole text until you reach the line intend to be deleted. The while loop has 1 truth condition which makes it loop till it reaches the EOF character and then it breaks out of the while loop. Home Delete a specific line from a text file using C. Leonhard P. Adam Hawes Adam Hawes 5, 1 1 gold badge 20 20 silver badges 29 29 bronze badges.

ReadAllLines fileIN ; foreach string line in data if! Equals "my line to remove" File. Delete fileIN ; File. Mauricio Kenny Mauricio Kenny 87 6 6 bronze badges. WriteLine reader. Frying Brains Frying Brains 11 1 1 bronze badge. Remove a block of code from multiple files To expand on Markus Olsson's answer, I needed to remove a block of code from multiple files.

WriteLine e. Open, FileAccess. ReadWrite , Encoding. Delete file ; File. WriteLine excpt. EndsWith ". Joel Wiklund Joel Wiklund 1, 2 2 gold badges 12 12 silver badges 20 20 bronze badges.

Why can't use this? ReadAllLines openFileDialog1. FileName ; Then look up the line you need to delete and replace it with "" : lines[x].

Replace lines[x], "" ; Done! Marty Brant Marty Brant 7 1 1 bronze badge. This doesn't remove the line from the file, all it does is make line x empty. Therefore if you were doing this a lot, you would just end up with a bunch of empty returns in the file, which could mess up the indexes.

It actually doesn't replace anything at all. Replace is a pure method! Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.

Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses.



0コメント

  • 1000 / 1000