#include <stdio.h>
|
|
int
remove (const char *path); |
Upon successful completion, reomve return 0. Otherwise, -1 is returned and the global variable errno is set to indicate the error.
If
path
specifies a directory,
remove (path);
is the equivalent of
rmdir (path);
Otherwise, it is the equivalent of
unlink (path);
/****************** this program shows deleting a file using remove **************/
#include <stdio.h>
int main()
{
char * name = "C:\nput.txt";
FILE *fp = fopen(name, "w+");
if (fp == NULL)
{
printf ("fopen failed\n");
return -1;
}
fprintf(fp,"hello world");
fclose(fp);
remove(name);
fp=fopen(name,"r");
if (fp == NULL)
{
printf ("file has been deleted already\n");
}
else
{
printf("remove failed\n");
return -1;
}
return 0;
}
Output
file has been deleted already
|
© 2005-2007 Nokia |