Why do we use a NULL  pointer in file handling with C

The reason why we use a NULL pointer in file handling with C is because, when we open  a file with read mode “r” then the problem with the compiler is that

It will not throw any kind of error or warning if it doesn’t the file as mentioned in the fopen function

Make sure, you know if a file exists before reading a file

 FILE *fptr;
    fptr=fopen("test.txt","r");
    if(fptr==NULL){
        printf("file doesn't exists\n");
    }

Furthermore, if we opened the file in write “w” mode, then, at that instant, if the file is absent it will create a new file and overwrites the file  if a file already exists

Mohammed Anees

Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

Leave a Reply

Your email address will not be published.