ADVERTISEMENT
ADVERTISEMENT

remove() function in C language with Example

Here, we are going to learn about the remove() function of library function stdio.h in C language with its syntax, example.
Submitted by Souvik Saha, on February 28, 2019

remove() function in C

The remove() function is defined in the <stdio.h> header file.

Prototype:

    int remove(const char* filename);

Parameters: const char *filename

Return type: int

Use of function:

When we are dealing with files then sometimes we need to erase or delete some files. In file handling, we use remove() function to erase the files. The prototype of the function remove() is int remove(const char* filename);

Here, filename is the name of the file which has to be erased. It returns zero if the file is successfully deleted and non zero if an error occurred.

remove() example in C

#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE* f;
    //Check the existence of that file
    if ((f = fopen("includehelp.txt", "r")) == NULL) {
        printf("File does not exist...\n");
    }
    else {
        printf("File is exist.\n");
    }
    fclose(f);

    //remove file
    if (remove("includehelp.txt"))
        printf("Remove error.....\n");
    else
        printf("File is removed\n");

    //Check the existence of that file
    if ((f = fopen("includehelp.txt", "r")) == NULL) {
        printf("File does not exist...\n");
    }
    else {
        printf("File is exist.\n");
    }

    fclose(f);

    return 0;
}

Output

remove() example in C language

C stdio.h Library Functions Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.