I'm trying to read a file containing wikipedia pages and turning them into a matrix of 0 and 1 depending on whether there is an arc between them. So that we call a function using this matrix to sort their [PageRank.][1] but it says segmentation fault. Any help would be much appreciated.
#include <stdlib.h>
#include <string.h>
#define SIZE 10000
int main(int argc, char
const * argv[]) {
int graphe[SIZE][SIZE] = {0};
FILE * file = NULL;
char chaine[SIZE] = "";//the line from fgets
char * page = malloc(SIZE * sizeof(char));//an array with all the first pages of the file
char ** tab = malloc(SIZE * SIZE * sizeof(char));//2D array containing all the pages
file = fopen("wiki-zulu.txt", "r");
if (file != NULL) {
int i = 0, j = 0, cpt = 0;
while (fgets(chaine, SIZE, file) != NULL) {
char * token = strtok(chaine, "|");
page[i] = * token;
while (token != NULL) {
tab[i][j] = * token;
token = strtok(NULL, "|");
j++;
cpt++;
i++;
}
for (int i = 0; i < cpt; i++) {
for (int j = 0; j < cpt; j++) {
for (int k = 0; k < cpt; k++) {
if (tab[i][j] == page[k] && i != j) {//comparing all values in the 2D array with the array of pages
graphe[i][k] = 1;//1 if there is a link between them
}
printf("%d\t", graphe[i][j]);
}
}
printf("\n");
}
free(page);
free(tab);
fclose(file);
}
}
return 0;
}```
[1]: https://i.stack.imgur.com/eITFZ.png