不调用system函数,如何删去文件?
解决者加分!
例如:copy old.bin to new.bin, then delete old.bin
Delete()
{
open file "old.bin"
read content to buffer.
create the new file "new.bin".
write the content of buffer to the new file.
delete the old file. //how to do this
}
Header File
stdio.h
Category
Input/output Routines
Syntax
#include <stdio.h>
int remove(const char *filename);
int _wremove(const wchar_t *filename);
Description
Removes a file.
remove deletes the file specified by filename. It is a macro that simply translates its call to a call to unlink. If your file is open, be sure to close it before removing it.
The filename string can include a full path.
Return Value
On successful completion, remove returns 0. On error, it returns -1, and the global variable errno is set to one of the following values:
EACCES Permission denied
ENOENT No such file or directory
函数名: remove
功 能: 删除一个文件
用 法: int remove(char *filename);
程序例:
#include <stdio.h>
int main(void)
{
char file[80];
/* prompt for file name to delete */
printf("File to delete: ");
gets(file);
/* delete the file */
if (remove(file) == 0)
printf("Removed %s.\n",file);
else
perror("remove");
return 0;
}