There will be one column of numbers for each string?
This is not code, it's just ideas for code!
Code:
char buff[BUFFSIZE];
int col_num = 0, r, c;
int **A;
fgets(buff, "%s", BUFFSIZE - 1; fileptr);
while(ok = (sscanf(buff, "%s", &garbage)) > 0) {
col_num++;
}
Now col_num should have your number of columns. Usually, it's no problem figuring out the column number, because the data itself will be ordered by rows, so when you are reading in the data, and you hit a newline char, then you know that's how many columns there are for that row.
Longest row, wins! (tells you how many columns there has to be in your matrix).
More ramblings:
Code:
You can use fgets to count your rows up, but save your column headers separately, so you'll have them, for later.
Once you know the # of rows and columns:
*A = malloc your outer row of pointers for A sizeof(int *)
A = malloc your inner column of integers for A using sizeof(int) this time
and read it into your array:
for(r = 0; r < rows; r++)
for(c = 0; c < cols; c++)
fscanf(fileptr, "%d", &A[r][c]);
Now you can get the column headers still in buff, (again with sscanf(), and print them, then print up a line of =========, and then start with your rows and cols of data, in a very similar way to how they were fscanf()'d from the file, above.
All the above is NOT code, it's just thinking aloud some thoughts in pseudo codish stuff, to give you some idea's.