I have a text file from which I read words. After that, I have to write in a binary file each word and near it the row and column where it appears. At _strdup(p) my programm crashes. Does anyone know why? I would appreciate your help. Here is the code:
void create(const char *filename, const char ****matrix) {
    FILE *u, *f;
    u = fopen(filename, "wb");
    assert(u != NULL);
    f = fopen("in.txt", "r");
    assert(f != NULL);
    (*matrix) = (char ***)malloc(sizeof(char **) * 1);
    int i = 0;
    int j=0; char buff[1024];
    while (fgets(buff, 1024, f)!=NULL) {
        (*matrix) = realloc((*matrix), (i + 1) * sizeof(char **));
        char *p = strtok(buff, " ().,");
        (*matrix)[i] = (char **)malloc(sizeof(char *));
        while (p) {
                (*matrix)[i] = (char **)realloc((*matrix)[i], sizeof(char *)*(j + 1));
                strcpy((*matrix)[i], buff);
                (*matrix)[i][j] = _strdup(p);
                fwrite((*matrix)[i][j], sizeof(char *), 1, u);
                fwrite(&i, sizeof(int), 1, u);
                fwrite(&i, sizeof(int), 1, u);
                j++;
                (*matrix)[i][j] = NULL;
            p = strtok(NULL, " ().,");
        }
        (*matrix)[i] = NULL;
        i++;
        printf("\n");
    }
    fclose(u);
    fclose(f);
}
 
     
    
