怎样关闭文件,并且不保存文件
C语言中“w”形式 fopen 一个文件,写了第一行了,发现不需要生成该文件,如果用fclose关闭这个文件,该文件也生成出来了,怎么样才能不让这个文件生成了呢?
[解决办法]
fopen执行完文件就已经被创建了,你不管调用不调用fclose都会被创建,如果你不需要这个文件可以在关闭后在删除。
[解决办法]
C语言中的Remove函数
简介:
功 能: 删除一个文件,相当于unlink函数,但是如果它的filename参数是一个目录的话,其作用就相当于rmdir函数。
用 法: int remove( const char *filename); remove函数图片头文件:在Visual C++ 6.0中可以用stdio.h也可以用io.h,前者更普遍。
返回值:如果删除成功,remove返回0,否则返回EOF(-1)。
[解决办法]
NAME remove - remove a file or directorySYNOPSIS #include <stdio.h> int remove(const char *pathname);DESCRIPTION remove() deletes a name from the file system. It calls unlink(2) for files, and rmdir(2) for directories. If the removed name was the last link to a file and no processes have the file open, the file is deleted and the space it was using is made available for reuse. If the name was the last link to a file, but any processes still have the file open, the file will remain in existence until the last file descriptor referring to it is closed. If the name referred to a symbolic link, the link is removed. If the name referred to a socket, FIFO, or device, the name is removed, but processes which have the object open may continue to use it.RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.ERRORS The errors that occur are those for unlink(2) and rmdir(2).