remove() in C Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In C, remove() is a standard library function is used to delete a file from the file system. It provides a simple way to manage files in the storage from a C program.Example: C #include <stdio.h> int main() { // Remove the file remove("gfg.txt") return 0; } OutputFile deleted successfully.Explanation: In this program, remove() function attempts to delete the file named "gfg.txt" from the current directory. If the file exists and permissions allow, it is deleted; otherwise, the operation fails.This article covers the syntax, uses and common example of remove() function in C:Table of ContentSyntaxExamples of remove()Delete Multiple FilesRemove Old Files to Add Latest DataSyntaxremove() is a standard library function defined in <stdio.h> header file in C.remove(filename)Parameters: filename: Name of the file to be deleted.Return Values:If deletion of file is successful, it returns 0.If deletion fails, it returns a non-zero value.This return value can be used to check whether the remove operation was successful or not.Examples of remove()The following examples demonstrate the use of remove() in C programs.Delete Multiple Files C #include <stdio.h> int main() { const char *fs[] = {"gfg1.txt", "gfg2.txt", "gfg.txt"}; int n = sizeof(fs)/sizeof(fs[0]); // Create files to delete for (int i = 0; i < n; i++) { FILE *f = fopen(fs[i], "w"); fclose(f); } // Delete multiple files using remove() in for loop for (int i = 0; i < n; i++) { if (remove(fs[i]) == 0) printf("Deleted %s.\n", fs[i]); else printf("Failed to delete %s.\n", fs[i]); } return 0; } OutputDeleted gfg1.txt. Deleted gfg2.txt. Deleted gfg.txt. Remove Old Files to Add Latest DataThe remove() function can be used to delete old files from the system ensuring the current file always contains latest data. C #include <stdio.h> int main() { const char *filename = "gfg.txt"; // Check and remove existing file if (remove(filename) == 0) printf("Old file deleted.\n"); else printf("No existing file to delete.\n"); // Create a new file FILE *fptr = fopen(filename, "w"); // Check file exist or not if (fptr != NULL) printf("new file is created"); // writing logic here...... fclose(fptr); return 0; } OutputNo existing file to delete. new file is created Comment More infoAdvertise with us Next Article rewind() in C R ritikk5g6k Follow Improve Article Tags : C Language C-Functions File Handling Similar Reads rewind() in C In C, rewind() is a built-in function used to reset the given file pointer to the beginning of a file allowing the read and write from the beginning once again in the program without reopening the file.Example:C#include <stdio.h> int main() { FILE *fptr = fopen("file.txt", "w+"); // Write data 3 min read Tokens in C In C programming, tokens are the smallest units in a program that have meaningful representations. Tokens are the building blocks of a C program, and they are recognized by the C compiler to form valid expressions and statements. Tokens can be classified into various categories, each with specific r 4 min read strrev() function in C The strrev() function is a built-in function in C and is defined in string.h header file. The strrev() function is used to reverse the given string. Syntax:char *strrev(char *str);Parameter:str: The given string which is needed to be reversed.Returns: This function doesn't return anything but the re 2 min read strrchr() in C The strrchr() function in C locates the last occurrence of a character in a string and returns a pointer to it. It is a standard library function defined inside <string.h> header file. Syntax : char* strrchr( char* str, int chr ); Parameter: str: specifies the pointer to the null-terminated st 2 min read strnset() function in C The strnset() function is a builtin function in C and it sets the first n characters of a string to a given character. If n is greater than the length of string, the length of string is used in place of n. Syntax: char *strnset(const char *str, char ch, int n); Parameters: str: This is the original 2 min read strcmpi() function in C The strcmpi() function is a built-in function in C and is defined in the "string.h" header file. The strcmpi() function is same as that of the strcmp() function but the only difference is that strcmpi() function is not case sensitive and on the other hand strcmp() function is the case sensitive. Sy 2 min read Like