Home  >  Article  >  Backend Development  >  C program to delete files

C program to delete files

王林
王林forward
2023-08-25 16:41:032439browse

C program to delete files

In programming, processing files is very important. Each programming language has its own set of functions or libraries to help manipulate files.

In the C programming language, there is also a function called remove that programmers can use to delete files.

The remove() function in C programming

The remove function is used to delete the file with the specified name. This function is located in the stdio header file.

Syntax

remove (“file_name”);

Parameters

This function accepts one parameter, which is the name of the file to be deleted.

The file name can also be the path of the file, but only if the system supports it.

Return value

Returns zero if the delete operation completes successfully; otherwise returns a non-zero value on failure.

Example

#include<stdio.h>
int main() {
   int del = remove("textFile.txt");
   if (!del)
      printf("The file is Deleted successfully");
   else
      printf("the file is not Deleted");
   return 0;
}

Output

The file is Deleted successfully

The above is the detailed content of C program to delete files. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete