by Dinesh Thakur Category: File Handling

The prototype of this function is given below.

int remove(const char* filename);

After the operation of the above function, the file is no longer accessible with the name given as the argument. The subsequent attempts to open the file with the same name will fail unless it is created again with that name.

Illustrates the functions remove()

#include <stdio.h>

#include <stdlib.h>
void main()
   FILE* fptr ;
   fptr = fopen("Student file", "w");
   if( fptr == NULL)  //test if fopen () fails to open file. /
        printf("File could not be opened.");
        exit (1);
        printf("File Student_file is open for writing.\n");
        remove ("Student_file");
        if(remove ("Student_file") != 0) // test for removal
          printf ("Student_file is removed. \n");
          freopen ("Student_file", "a", fptr);
                     /* reopen file for appending*/
          if(fptr ==NULL)
             printf( "Failed to reopen");
                            printf ("Student_file is opened again. \n");
                            fclose (fptr);

Function remove() in C

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.