I am a learning file handling in C. I tried implementing a program but no matter what I do the file pointer is still null.
I checked the spelling, the directory, even tried adding and removing .txt extension but I still don't get what is wrong with this program.
#include <stdio.h>
int main()
{
FILE *fptr1;
char filename[100], c;
printf("Enter the filename to open for reading: ");
scanf("%s", filename);
fptr1 = fopen(filename, "r");
if (fptr1 == NULL)
{
printf("Cannot open file %s \n", filename);
}
do {
c = fgetc(fptr1);
printf("%c", c);
} while (c != EOF);
fclose(fptr1);
return 0;
}