I'm trying to send a file to a function that creates a matrix of a struct called Entry, populates it based on the file, and returns the matrix. Right now it's a cascade of errors that I can add if needed, but I suspect I'm just making multiple dumb errors. If there's an easier way that doesn't involve malloc, that would work just as well.
What am I doing wrong and how can I do this properly?
Here's the relevant code:
Entry **matCreate(FILE *fp){
// initialize matrix
Entry matrix = malloc(states * N_CC * sizeof(Entry));
// populate the matrix with initial values
for (int i = 0; i < states; i++) {
for (int j = 0; j < N_CC; j++) {
matrix[i][j].next = 99;
matrix[i][j].action = "D";
}
}
return matrix;
}
and in the main function:
Entry **matrix = matCreat(fp);
I'm starting the function off with
Entry **matCreate(FILE *fp){
Initializing it with
Entry (*matrix)[N_CC] = malloc( states * sizeof *matrix );
Populating it with:
for (int i = 0; i < states; i++) {
for (int j = 0; j < N_CC; j++) {
matrix[i][j].next = 99;
matrix[i][j].action = "D";
}
}
And getting it from main with: Entry ourMat = (*matCreate(fp))[N_CC];
But still getting the error: tokenize.c:84:1: warning: return from incompatible pointer type [enabled by default]
Where am I going wrong?