0
int lineInputs = 0;

cin >> lineInputs;

int whatever = 0;

char* myArray = new char[arrayElements*lineInputs];

int j =0;

for(int i = 0; i < lineInputs; i++)
{
        cin >> whatever;
    for(j; j<total; j+=39)
    {
        for(int nom=0; j<arrayElements; nom++)
        {
            cin >> myArray[j];
        }
    }

}

In my forloop say i have lineInputs = 4 and total = 156

Meaning 4 times we do this, we want to insert 156 chars into my array. But we want to make it so that every 40 characters we continue entering the array.

Bsically we need to insert this input into the array but i feel like my forloops are messed up. This will be the input

4 
1 
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH 
2 
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 
3 
HHTTTHHTTTHTHHTHHTTHTTTHHHTHTTHTTHTTTHTH 
4 
HTHTHHHTHHHTHTHHHHTTTHTTTTTHHTTTTHTHHHHT

The first line 4 meaning 4 of these 40 character lines. And the number above the character lines just signifying line 1 2 3 4 ect.

How can i attempt this right?

So the array would basically look like this.

HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTHHTTTHHTTTHTHHTHHTTHTTTHHHTHTTHTTHTTTHTHHTHTHHHTHHHTHTHHHHTTTHTTTTTHHTTTTHTHHHHT

soniccool
  • 5,790
  • 22
  • 60
  • 98
  • 1
    I would suggest to stop mixing C and C++: Use `std::string` instead of `char*`. (This doesn't solve your problem, but it hurts my eyes) What's `arrayElements` by the way? it's not specified anywhere. – stefan Dec 28 '12 at 11:49

1 Answers1

1

You are making the same fundamental mistake you made in your other question, which is to fail to treat the input array correctly. You are repeatedly reading into the first 40 characters of myArray. What you need to do is read the first line into the first 40 characters, the second line into characters 40 to 79, etc.

Better yet, make it a two dimensional array so that you don't have to muck around with computing the indices.

Even better, make it an array of std::string rather than an array of char.

David Hammen
  • 32,454
  • 9
  • 60
  • 108