I need to initialise FILE *fi in different function. This example code shows the problem.
#include<iostream>
using namespace std;
void init(FILE* fi)
{
fi=fopen("in.txt", "r");
if(fi==NULL)
{
cout<<"Got NULL\n";
}
}
int main()
{
FILE* fi;
init(fi);
if(fi==NULL)
{
cout<<"NULL\n";
return 0;
}
return 0;
}
The program outputs NULL (not "Got NULL"), and I don't have a clue how to make it work...
It is important that I have fi passed as a pointer, not getting it as a return value.