Powinno działać, ale nie testowałem dość dokładnie:
https://wandbox.org/permlink/Yfk1dAutbQ7UJ0Ro
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
int scanLineForDoubles(const char *line, double **allocsTable)
{
double x;
char *p = (char *)line;
int count = 0;
errno = 0;
while (p && *p)
{
char *oldP = p;
x = strtod(p, &p);
if (oldP == p)
break;
*allocsTable = realloc(*allocsTable, (count+1)*sizeof(**allocsTable));
(*allocsTable)[count++] = x;
}
return count;
}
void freeMatrix(double **matrix, int columntCount)
{
if (!matrix || !columntCount) return;
for (int i = 0; i < columntCount; ++i)
free(matrix[i]);
free(matrix);
}
int loadMatrix(FILE* f, double ***allocMat, int *resultRowSize)
{
int count = 0;
int rowSize = 0;
char line[0x400];
while (fgets(line, sizeof(line), f))
{
double *row = NULL;
int newRowSize = scanLineForDoubles(line, &row);
if (newRowSize <= 0) break;
if (!rowSize) {
rowSize = newRowSize;
} else {
if (rowSize != newRowSize) {
freeMatrix(*allocMat, count);
*allocMat = NULL;
return -1;
}
}
*allocMat = realloc(*allocMat, (count+1)*sizeof(**allocMat));
(*allocMat)[count++] = row;
}
*resultRowSize = rowSize;
return count;
}
int main(void)
{
double **m = NULL;
int rowSize = 0;
int columnSize = loadMatrix(stdin, &m, &rowSize);
int i, j;
printf("(%d , %d)\n", columnSize, rowSize);
for (i = 0; i < columnSize; ++i) {
for (j = 0; j < rowSize; ++j) {
printf("%8lg ", m[i][j]);
}
printf("\n");
}
freeMatrix(m, columnSize);
return EXIT_SUCCESS;
}