as

Thursday 13 November 2014

Check if file exists in C

Below program shows how to check if file exists or not.


#include<stdio.h>             

#include<stdlib.h>

void main()
{
      // here declare a file in pointer.
    FILE *filep;                          
     
      // try to open a text file at location c:\abc.txt.
     
      //if file exists, fopen will return not null pointer
    filep =fopen("c:\\abc.txt","r");
     
    if (!filep)
     {
      printf ("File does not exist\n");
      getchar();
     }
    else
     {
      printf("File exists at given location");
     }
}







No comments:

Post a Comment

Leave your valuable feedback. Your thoughts do matter to us.

Sponsored Links

Popular Posts

Comments

ShareThis