Segmentation fault(core dumped)

Well... This is my code and I encounter Segmentation fault(core dumped)... I found where it is but I don't know why. How can add one to a integer cause a Segmentation fault(core dumped)?
P.S. This is about doing a bingo games.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
#include<string.h>

int main() {
  int players, size;
  scanf("%d%d", &players, &size);
  int board[players][size][size];
  int i=0, j, k;
  char name_list[players][64];
  while(i<players){
    scanf("%s", name_list[i]);
    for(j=0; j<size; j++){
      for(k=0; k<size; k++){
        scanf("%d", &board[i][j][k]);
      }
    }
    i++;
  }

  int move;
  int m=0, n=0;
  int row=0, col=0, diag=0;
  int win=0;
  int winner_list[players];
  int win_number;
  while(m<(size*size)){
    scanf("%d", &move);
    for(i=0; i<players; i++){
      for(j=0; j<size; j++){
        for(k=0; k<size; k++){
          board[i][j][k]=0;
        }
      }
    }

    for(i=0; i<players; i++){
      printf("player %d\n", i);
      win=0;
      for(j=0; j<size; j++){
        for(k=0; k<size; k++){
          if(board[i][j][k]==0)
            row++;  //Cause Segmentation fault(core dumped)
          if(board[i][k][j]==0)
            col++;  //Cause Segmentation fault(core dumped)
          if(col==size || row==size){
            win=1;
            winner_list[n]=i;
            win_number=move;
            n++;
            break;
          }
          if(j==k && board[i][j][k]==0)
            diag++; //Cause Segmentation fault(core dumped)
        }
        row=0;
        col=0;
        if(win==1)
          break;
      }
      if(diag==size){
        win=1;
        winner_list[n]=i;
        win_number=move;
        n++;
        diag=0;
      }
      printf("CHECKPOINT!!!\n");
      printf("i: %d\n", i);
    }
    if(win==1)
      break;
  }

  printf("%d ", win_number);
  for(i=0; i<sizeof(winner_list); i++){
    printf("%s ", name_list[winner_list[i]]);
  }

  return 0;
}
My first suggestion is that you stop using VLAs and either make your arrays statically allocated or use malloc()/free() to dynamically allocate the arrays.

Topic archived. No new replies allowed.