How to remove a file in C program?

后端 未结 4 1224
礼貌的吻别
礼貌的吻别 2020-12-04 02:30

How do I close a file and remove it?

I have the following code:

FILE *filePtr = fopen(\"fileName\", \"w\");
...

Now I want to close

4条回答
  •  情话喂你
    2020-12-04 03:07

    As man unlink(2) says (for Unix systems) :

    The unlink() function removes the link named by path from its directory and decrements the link count of the file which was referenced by the link. If that decrement reduces the link count of the file to zero, and no process has the file open, then all resources associated with the file are reclaimed. If one or more process have the file open when the last link is removed, the link is removed, but the removal of the file is delayed until all references to it have been closed.

    So the order doesn't matter at all.

提交回复
热议问题