Search code examples
cfopen

C - fopen invalid file


I am wondering, how to check if I am opening file which exists with fopen? I want to diplay some message, when user selects file with bad name. Is must be some simple checking, but I am not able to solve it.

Thanks


Solution

  • in your param list:

    FILE pFile ;
    

    then:

      pFile = fopen ("myfile.txt","r");
    
    if (pFile == NULL)
    printf("No Such File !! ");