YouTip LogoYouTip

C Function Remove

# C Library Function - remove() ## Description The C library function **int remove(const char *filename)** deletes the given file name **filename**, so that it can no longer be accessed. ## Declaration Below is the declaration for the remove() function. ```c int remove(const char *filename) ## Parameters * **filename** -- This is a C string containing the name of the file to be deleted. ## Return Value If successful, it returns zero. If an error occurs, it returns -1 and sets errno. ## Example The following example demonstrates the usage of the remove() function. ```c #include #include int main () { int ret; FILE *fp; char filename[] = "file.txt"; fp = fopen(filename, "w"); fprintf(fp, "%s", "This is .com"); fclose(fp); ret = remove(filename); if(ret == 0) { printf("File deleted successfully"); } else { printf("Error: unable to delete the file"); } return(0); } Let's assume we have a text file **file.txt**, with the following content. We will use the program above to delete this file. Let's compile and run the above program, which will produce the following message, and the file will be permanently deleted. File deleted successfully
← Sets SmembersLists Rpop β†’