I want to trigger a function with parameters just before exiting the program (exit by "return" in the main or by closing the console). My function will print the values of certain variables in a file.
Using the function "atexit" not help me because the pointer to the function is without parameters.
Thanks
P.S. My major problem is when I interrupt the execution of my program by closing the console, I want to get tthe value of some variables at that moment :
ostream out("myFile.txt");
int **S;
int n;
...
void fn(void)
{
out << "S = " << endl;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
out << S[i][j] << " " << endl;
}
out << endl;
}
}
...
int main()
{
atexit(fn); // not working if i interrupt the execution
... // a big loop of code
return 0;
}
I think it will be easy to understand mu issue with this example.
Regards