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
Leave a Reply