I programmed it statically so the calling function always passes either 'd' or 'e'.
Examples:
Code:
fin = openfile(filename, 'd');
fout = openfile(filename, 'e');
EDIT: I updated the function to return NULL if the flag isn't 'd' or 'e'.
Code:
FILE *openfile(char *filename, char flag) {
FILE *fin = NULL, *fout = NULL;
if (flag == 'd') {
fin = fopen(filename, "r");
if (fin == NULL) {
fprintf(stderr, "Error: Unable to open %s\n", filename);
exit(EXIT_FAILURE);
}
return fin;
}
else if (flag == 'e') {
fout = fopen(filename, "w");
if (fout == NULL) {
fprintf(stderr, "Error: Unable to create %s\n", filename);
exit(EXIT_FAILURE);
}
return fout;
}
else
return NULL;
}
This wouldn't happen, but it does seem to have fixed the warning. Is this the only way to get rid of the warning?