What is remove in C?

The remove function deletes the file with the filename given as a parameter. This is depicted below:

Library

The function is accessible via the stdio.h library.

Parameters

A string containing the name of the file to be deleted is given as a parameter.

Syntax

int remove(const char* filename)

Return values

On successful execution, the function returns 0. Otherwise, a non-zero number is returned.

Code

main.c
this_file.txt
#include <stdio.h>
#include <string.h>
int main() {
int ret;
char filename[] = "this_file.txt"; // name of the file to be deleted
ret = remove(filename); // call the remove function
if(ret == 0) //succesful deletion
{
printf("The file was deleted.");
}
else // unsuccessful deletion
{
printf("Unable to delete file.");
}
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved