I wrote this program by seeing a YouTube video.
In that, he used fopen_s
instead of fopen
and I have the latest gcc and g++
compiler installed, but they don't support fopen_s
. I am running into an error to close the file.
#include <stdio.h>
int main(){
FILE* file;
printf("loading file\n");
file = fopen("testFile.txt", "r+");
if (file == NULL){
printf("ERROR!!!");
fclose(file);
return 1;
}
printf("file pointer is loded\n");
fclose(file);
return 0;
}
This is the output
loading file
Segmentation fault (core dumped)
What's going wrong?