Syntax
#include <stdio.h> /* also in <io.h> */ int unlink(const char *pathname);Description
unlink deletes the file specified by pathname.
Portability Note For portability, use the ANSI/ISO function remove instead of unlink.
unlink returns 0 if the file is successfully deleted. A return value of -1 indicates an error, and errno is set to one of the following values: compact break=fit.
Value
This example deletes the file tmpfile from the system or prints an error message if unable to delete it.
#include <stdio.h>
int main(void)
{
if (-1 == unlink("tmpfile"))
perror("Cannot delete tmpfile");
else
printf("tmpfile has been successfully deleted\n");
return 0;
/****************************************************************************
If the file "tmpfile" exists, the output should be:
tmpfile has been successfully deleted
****************************************************************************/
}
Related Information