

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove function in C/C++
The C library function int remove(const char *filename) deletes the given filename so that it is no longer accessible.
Following is the declaration for remove() function.
int remove(const char *filename)
This function takes the filename. This is the C string containing the name of the file to be deleted. On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
Example
#include <stdio.h> #include <string.h> int main () { int ret; FILE *fp; char filename[] = "file.txt"; fp = fopen(filename, "w"); fprintf(fp, "%s", "This is tutorialspoint.com"); fclose(fp); ret = remove(filename); if(ret == 0) { printf("File deleted successfully"); } else { printf("Error: unable to delete the file"); } return(0); }
Let us assume we have a text file file.txt having some content. So we are going to delete this file, using the above program. Let us compile and run the above program to produce the following message and the file will be deleted permanently.
Output
File deleted successfully
- Related Questions & Answers
- List remove() function in C++ STL
- Remove Interval in C++
- Remove Boxes in C++
- Remove 9 in C++
- How to remove a function at runtime in PHP?
- How to Use the Remove function in Lua programming?
- LinkedList Remove method in C#
- forward_list::remove() in C++ STL
- Remove Covered Intervals in C++
- Remove K Digits in C++
- Remove Invalid Parentheses in C++
- Remove Duplicate Letters in C++
- How to remove a function from an object in JavaScript?
- Remove K Digits in C++ program
- iswlower() function in C/C++
Advertisements