Improve this question. Ben Basically so far I'm scanning the file line by line using fgets, storing the line in a string, comparing it with str. If it's not a match, go to the next line. But how do I proceed from there? Suppose I find str on the second line of the file.. Add a comment. Active Oldest Votes. You are essentially asking the same thing as here: Delete a Line from a file in C Language , and also here: deleting a string from a particular position in a file You will have to load the file into memory, edit it there, and then write it back to the disk.
Improve this answer. Community Bot 1 1 1 silver badge. The way I see it, I should scan the file till I find str, write whatever is before and after str into a temporary file, and then copy the content of that temporary file back into the original file.
How do I go to a particular position in the file? To read a line into a file, use fread or fgets — cegfault. OR the path is a directory. OR the path specified a read-only file. Below are the programs to illustrate the File. Delete String method. Program 1: Before running the below code, a file file. IO namespaces using System; using System. Delete myfile1 ; File. WriteLine "Specified files have been deleted. After running the above code, above output is shown and two existing files file.
Skip to content. Change Language. Related Articles. Now open the file that you want to delete the line from. As you reach the newline character, increment the number of line variable, so you have a clear idea about the line you want to delete.
Copy paste the whole text until you reach the line intend to be deleted. Otherwise, please be thoughtful, detailed and courteous, and adhere to our posting rules. Edit Preview. H1 H2. Post Reply. Broken Link. Go Back to the Post Continue Anyways. Share Post. Permanent Link. Insert Code Block.
0コメント