How to delete from a .txt file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to delete from a .txt file

So I'm making a program for a library with books number of books and book id and I'm trying to make a delete function to delete a certain book/line of text. any help would be appreciated.

9th May 2020, 6:01 PM
PIZZA
PIZZA - avatar
1 Answer
0
1. Read in the entire text file to memory ( or in chunks for big files ) 2. Delete what you want 3. Write the entire thing back to file. Be aware that anything can happen while you're writing back to the file. So in order to not end up with a corrupted file it's probably a good idea to create a backup before writing, and then deleting it again when writing is complete. You can use these functions from the stdio.h header for that: https://en.cppreference.com/w/c/io/rename https://en.cppreference.com/w/c/io/remove
9th May 2020, 9:23 PM
Dennis
Dennis - avatar