Question: I have attached my full source code of my program that can open a `.txt` file. It doesn't execute after the `cout << length`. I am trying to store the `.txt` file information in memory by using an array.

```
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

char filename[128];
char file[10][250];
int count;
int length;
string line;

int main ()
{
    int count = 0;
    int length = 0;
    cout << "Filename: ";
    cin.clear();
    cin.getline(filename, sizeof(filename));
    string new_inputfile(filename);
    ifstream inputfiles (new_inputfile.c_str());
    if(!inputfiles.is_open())
    {
        cout << "File could not be opened. \n ";
    }
    else
    {
        for (int i=0; getline(inputfiles,line); i++)
        {
            length++;
        }

        cout << length;
//      char file[length][250]; <- How can I create the array based on the length variable?
// CODE DOES NOT EXECUTE AFTER THIS.
        while(!inputfiles.eof() && (count<10))
        {
            inputfiles.getline(file[count],250);
            count++;
        }

        for(int i=0; i < count; i++)
        {
            cout << file[i] << endl;
        }

    }
    inputfiles.close();
    return 0;
}

```

Also, since `file[]` is char, say for example `file[1]` contained the char `Name=Mike`, how do I strip off everything before the `=`. I want just `Mike`. I know with `string`, I can use `substr()` method, but I don't know for `char`.

Answer: 
This is horribly wasteful way to count number of lines in a file.

```
for (int i=0; getline(inputfiles,line); i++) // i is also completely useless here
{
     length++;
}

```

You're reading the whole file only to throw everything away and start again! And after this loop is done, `inputfiles.eof()` will be `true` and you'll never enter neither the next `while` loop nor the last `for` loop (because `i == count`). Execution skips directly to `inputfiles.close()` and then you return from `main`.

I suggest you work on the `line` string as you go:

```
for ( ; getline(inputfiles, line); )
{
     // do stuff with line and ditch the global char arrays
}

```

If you want store the lines for later, well, just save them :) The easiest thing to do is to use a [vector](http://en.cppreference.com/w/cpp/container/vector):

```
std::vector<std::string> all_them_lines;
while (getline(file, line) all_them_lines.emplace_back(line);

```

There, the entire file is now saved in `all_them_lines`, line by line. You can access them just like you would in an array, like `all_them_lines[0]`. You also don't need to know the number of lines beforehand - vectors expand automatically when you add stuff to them.

Now to parse a line and extract formatted input from it, check out what [`stringstream` class](http://en.cppreference.com/w/cpp/io/basic_stringstream) has to offer.
You asked:

> 
> 
> ```
> //      char file[length][250]; <- How can I create the array based on the length variable?
> 
> ```
> 
> 

Declare `file` as:

```
char (*file)[250] = NULL;

```

and then,

```
file = new char[length][250];

```

Make sure you call `delete [] file` before the end of the function.

You said:

> 
> 
> ```
> // CODE DOES NOT EXECUTE AFTER THIS.
> 
> ```
> 
> 

You can [rewind the stream](http://en.cppreference.com/w/cpp/io/basic_istream/seekg) and start reading from it again.

```
    inputfiles.seekg(0);
    count = 0;
    while(!inputfiles.eof())
    {
        inputfiles.getline(file[count],250);
        count++;
    }

```