I was wondering what the easiest way to delete a file (say a .txt file) is. I have found several examples of creating, reading and writing , but no deletion. Any help would be appreciated.
remove(strFileName);
I don't like standard description of this function:
"The remove function causes the file whose name is the string pointed to by strFileName to be no longer accessible by that name."
But this function actually delete files.
(will not work with directories).
I think the reason the wording is like that is because it's not the job of C to specify that much about the underlying environment. In other words, it's the operating system's job to implement how this is actually done. It may be that the file isn't actually deleted from disk right away, but that the OS does exactly what the description says: change things in such a way that the file can no longer be accessed by its previous name.
I agree that it's a bit confusing for someone that's just looking to delete a file, but the language definition must be very precise about such things. After all, this is what C tutorial books are for, where you will probably find a looser explanation of functions like remove().
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.