Simple Delete File Program in ANSI C for Windows

和自甴很熟 提交于 2019-12-10 22:05:43

问题


Looking for a simple program to a delete a file written in ANSI C.
Just as an example how would you delete a file at "C:\test.txt" with C?


回答1:


You can delete a file from the OS using the remove() function. Like so:

#include <stdio.h>
int main(){
    if(remove("HELLO.txt") == -1)
        perror("Error in deleting a file");
    return 0;
}

The remove() function is defined in stdio.h. Here are some docs.




回答2:


Use the remove function. I believe it is in "stdio.h"




回答3:


remove or unlink

remove is declared in 'stdio.h'

unlink is declared in 'unistd.h'

unlink is posix function, remove is ansi C function. They all work fine in windows.

unlink only delete files, remove can be used to delete directories.



来源:https://stackoverflow.com/questions/11948324/simple-delete-file-program-in-ansi-c-for-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!