I want to create the function that opens a file and then other functions use this opened file. This is my code,
#include <stdio.h>
int openFile(FILE* inputFile)
{
inputFile = fopen("input.txt", "r");
if (inputFile != NULL)
return 0;
else
return -1;
}
void readWholeFile(FILE* inputFile)
{
char str[20];
while (feof(inputFile)) {
fscanf(inputFile, str);
printf("%s\n", str);
}
}
int main() {
FILE* inputFile;
if (openFile(inputFile) == 0) {
readWholeFile(inputFile);
}
else
printf("File didn't open");
fclose(inputFile);
return 0;
}
"File didn't open" is not printed so the file should be opened but actually readWholeFile prints nothing as a file would be empty. What's the problem?