The following code is giving me a segfault, and I have no idea why. It is the only code in my main function other than return 0 at the end. Also, it successfully prints “fr opened.”
//create file pointer and open file
FILE *fr;
fr = fopen("IntegerArray.txt", "r");
if(fr = NULL){
printf("fr is null\n");
}
else{
printf("fr opened\n");
}
int ch = fgetc(fr);
ch = fgetc(fr);
You’re assigning NULL to the FILE* you open.
Change
to