I have problem with a static variable.
I tried to make maze program by using stack.
At first, it activates currently when I put all codes in same source file.
But after I separate main to main.c source, and other functions to function.c, an error occurred at static variable.
This is part of code in function.c file that problem happen.
I used EXIT_ROW and EXIT_COL as static variable, and these
initialized at main function.
And I use EXIT_ROW and EXIT_COLS at other function.c file
but when I do debugging this file, EXIT_ROW and EXIT_COL didn't initialize at all.
void main()
{
int xsize, ysize;
FILE *fp;
if( !( fp = fopen("input.txt", "r") ) )
{
fprintf(stderr, "FILE couldn't open\n");
exit(EXIT_FAILURE);
};
fscanf(fp, "%d %d", &ysize, &xsize);
EXIT_ROW = ysize;
EXIT_COL = xsize;
printf("%d %d\n", ysize, xsize);
init_maze(xsize, ysize, fp);
print_maze(xsize, ysize);
path();
}
I couldn't understand why it happened.. EXIT_ROW and EXIT_COLS are declared in stack.h header file. can u help me why it happened, and how can I fix it?
EXIT_ROWandEXIT_COLSyou need to show exactly how and where that is defined. But if they are indeed declared as globalstaticthen of course they can only be accessed within each file. That is what thestatickeyword does. So in fact you would have two independent versions of each of those variables - one set for each file.staticcan mean two things: on "global level", it says "only to be known in this compilation unit" (Your case, apparently. We could say definitely, if you had shown the variable definition and where it is. Within functional scope,staticmeans a different thing.externdeclaration of those variables.