I’m trying to create a dialog box at the start of my program that allows the user to input a number that is then used in another function (actually in another C file) much later on in the program.
void function()
{
double variable;
char buf[256] = "400";
sprintf( buf, "%d", variable);
#ifdef WIN32
edit_dialog(NULL,"Enter variable", "Please enter the variable:", buf,260);
#endif
variable = atof(buf);
}
I’d like to pass ‘variable’ into another function later on in the program. The problem is, I don’t need the variable until much later. I don’t want to pass it between each and every function until it gets to the right part of the program. How do I do this?
Also when I launch this, I get the dialog box as I’d expect but the number in the box is not 400, as I would expect. Instead it is 2089881670(!) I assume I am handling memory incorrectly but don’t understand why.
For the 2089881670 problem, you should initialize your
variablelike this :double variable=0;For the variable created somewhere and used far far away, you could use a global/static variable (sic), like this :