You must pass N as part of the matrix type to your ReadMatrix function, and since it is not known at compile time, you must pass these as arguments too:
int readMatrix(FILE *file, size_t M, size_t N, char *matrix[][N]);
You could indeed also specify the array argument as char *matrix[M][N], but the first dimension size M is ignored for a function argument as it only receives a pointer to the array.
Here is an example:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int readMatrix(FILE *file, size_t rows, size_t cols, char *matrix[][cols]) {
int rc = 0;
for (size_t i = 0; i < rows; i++) {
for (size_t j = 0; j < cols; j++) {
char buf[80];
if (rc == 0 && fscanf(file, "%79s", buf) == 1) {
matrix[i][j] = strdup(buf);
} else {
matrix[i][j] = NULL;
rc = -1;
}
}
}
return rc;
}
int main(void) {
size_t rows, cols;
if (scanf("%zu %zu", &rows, &cols) != 2)
return 1;
char *mat[rows][cols];
if (readMatrix(stdin, rows, cols, mat) == 0) {
for (size_t i = 0; i < rows; i++) {
for (size_t j = 0; j < cols; j++) {
printf(" %8s", mat[i][j]);
}
printf("\n");
}
}
for (size_t i = 0; i < rows; i++) {
for (size_t j = 0; j < cols; j++) {
free(mat[i][j]);
}
}
return 0;
}
int readMatrix(FILE *file, size_t m, size_t n, char *matrix[m][n]);and callreadMatrix(file, M, N, A);char*is not the same as achar***. your compiler shouldn't accept any of this.