I am trying to get a user to enter a specific file name and have the program be able to read it.
FILE *fp;
char file[10];
fgets(file, sizeof(file), stdin);
fp = fopen(file, "r");
if (fp == NULL) {
printf("File doesn't open\n");
return 1;
}
This is a section of my code and what i'm currently trying to do. When i run the program and enter the file name, the output is "File doesn't open" which is my error message.
fprintf(stderr, "File %s did not open: %s\n", file, strerror(errno));in case of error