Question: I am trying to read the unknown contents of a text file into a 2D array and have it come out looking like:

```
M [0] [0]=2 M [0] [1]=1 M [0] [2]=0
M [1] [0]=0 M [1] [1]=1 M [1] [2]=3
M [2] [0]=8 M [2] [1]=9 M [2] [2]=1
M [3] [0]=3 M [3] [1]=5 M [3] [2]=2

```

when the text file looks like this:

```
2
1 0
0 1
3
8 9 1
3 5 2
-2 3 -1
0

```

The zero at the end shows the end of the file.

My problem is the array can be a max size of 10X10 so there is no way of knowing what the size of the 2D array is and how to get it to look like i have shown above. 

Any ideas?

Answer: 
For some dimensions N x M

```
char c;
int x;
for(int i = 0; i < N; i++)
{
for(int j = 0; j < M; j++)
{
  c = fgetc(file);
  if(c == ' ') continue;
  if(c == EOF) return;
  if(c == '-')
  {
      c = fgetc(file);
      x = -1 * ((int)c);
  } else {
      x = c;
  }
  if(x == 0)
  {
      array[i][j] = x;
  } else {
      return;
  }
}
}

```

But if you're talking about "what's the size of the matrix required to store these" then you're going to need a way to figure out what dimensions you want.
So all row of the array have 3 values?  

Simply read the values into the array keeping a count of which column you are in and ignore the newlines?

Look at getline