Skip to main content

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activateit activates currently when I put all codes in same source file.

But after I separate main to main.cmain.c source, and other functions to function.cfunction.c, an an error occurred at static variable.

thisThis is partspart of code in function.cfunction.c file that problem happen.

I used EXIT_ROWEXIT_ROW and EXIT_COLEXIT_COL as static variable, and these initialized at main function. And I use EXIT_ROWEXIT_ROW and EXIT_COLSEXIT_COLS at other function.cfunction.c file but when I do debugging this file, EXIT_ROWEXIT_ROW and EXIT_COLEXIT_COL didn't ititializeinitialize at all.

void main() { int xsize, ysize; FILE*FILE fp;*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 declaireddeclared in stack.h header file. can u help me why it happendhappened, and how can I fix it?

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activate 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 parts 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 ititialize 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 declaired in stack.h header file. can u help me why it happend, and how I fix it?

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?

added 82 characters in body
Source Link
Mohit Jain
  • 30.6k
  • 8
  • 80
  • 104

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activate 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 parts 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 ititialize 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 declaired in stack.h header file. can u help me why it happend, and how I fix it?

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activate 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 parts 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 ititialize 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 declaired in stack.h header file. can u help me why it happend, and how I fix it?

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activate 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 parts 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 ititialize 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 declaired in stack.h header file. can u help me why it happend, and how I fix it?

Improved body.
Source Link

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activate 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 parts of code in function.c file that problem happen.

void path(void) { int i, row, col, nextRow, nextCol, dir, found = FALSE; element position; mark[1][1] = 1; top = 0; stack[0].row = 1; stack[0].col = 1; stack[0].dir = 1; while(top>-1 && !found){ position = pop(); row = position.row; col=position.col; dir = position.dir; while(dir < 8 && !found) { nextRow = row + move[dir].vert; nextCol = col + move[dir].horiz; if(nextRow == EXIT_ROW && nextCol == EXIT_COL) found = TRUE; else if( !maze[nextRow][nextCol] && !mark[nextRow][nextCol]) { mark[nextRow][nextCol] = 1; position.row = row; position.col = col; position.dir = ++dir; push(position); row = nextRow; col = nextCol; dir = 0; } else ++dir; } } 

in this function, 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 ititialize 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 declaired in stack.h header file. can u help me why it happend, and how I fix it?

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activate 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 parts of code in function.c file that problem happen.

void path(void) { int i, row, col, nextRow, nextCol, dir, found = FALSE; element position; mark[1][1] = 1; top = 0; stack[0].row = 1; stack[0].col = 1; stack[0].dir = 1; while(top>-1 && !found){ position = pop(); row = position.row; col=position.col; dir = position.dir; while(dir < 8 && !found) { nextRow = row + move[dir].vert; nextCol = col + move[dir].horiz; if(nextRow == EXIT_ROW && nextCol == EXIT_COL) found = TRUE; else if( !maze[nextRow][nextCol] && !mark[nextRow][nextCol]) { mark[nextRow][nextCol] = 1; position.row = row; position.col = col; position.dir = ++dir; push(position); row = nextRow; col = nextCol; dir = 0; } else ++dir; } } 

in this function, I used EXIT_ROW and EXIT_COL as static variable, and these initialized at main function. but when I do debugging this file, EXIT_ROW and EXIT_COL didn't ititialize 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 declaired in stack.h header file. can u help me why it happend, and how I fix it?

I have problem with a static variable.

I tried to make maze program by using stack.

At first, It activate 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 parts 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 ititialize 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 declaired in stack.h header file. can u help me why it happend, and how I fix it?

Source Link
Loading