Help with homework problem???

The problem I'm working is writing a function that will accept 10 lines of user input, store the ten lines as ten individual c-strings, I'm supposed use a pointer array.  I'm having trouble actually assigning the input to my array?  Any help or guidance is appreciated.  Note:  I want help to learn, not an answer to the program.  Thanks!
#include <iostream>
#include <cstring>
using namespace std;
 
 
 
int main()
{
	int const NUMELS = 81;
	char *myArray[10];
	char myBuffer[810];
	char message[NUMELS];
	int i, j, pointerAddr, counter = 0;
	
 
	for (i = 0; i < 810; i+=81){
		myArray[counter++] = &myBuffer[i];
				
	}
	
	for (j = 0; j < 10; j++){
		cout << "Please enter a string: ";
		cin.getline(message, 81);
		myBuffer[i] = message[i];
		
		
	
	
	}
	cin.ignore(1);
	return 0;
 
 
 
 
 
 
 
}

Open in new window

jasonbrandt3Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Well, first of all, you only have 10 elements in 'myArray' but are initilizing 810 elements. That can't be what you want ;o)

Then, notice that they all point to the same buffer, just a little 'shifted'. That's also not what you want. You could either dynamically allocate memory or use a 2d array. The 1st approach would be like
        for (i = 0; i < 10; i++){
                myArray[i] = new char[NUMELS + 1];                     
        }
 
// ...
 
// delete the memory before exiting
 
        for (i = 0; i < 10; i++){
                delete [] myArray[i];                     
        }

Open in new window

0
jkrCommented:
Oh, and assigning the entered text requires copying it, e.g.
        for (j = 0; j < 10; j++){
                cout << "Please enter a string: ";
                cin.getline(message, 81);
                strcpy(myArray[i],message);
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
emceCommented:
firstly, think what i is in the for loop.
secondly you probably want to copy the characters from message into the right place in mybuffer.
0
jasonbrandt3Author Commented:
I got it!!!  the strncopy is what I was missing.  I'm using strncopy to populate myArray which indirectly copies to myBuffer.
0
Infinity08Commented:
>> Well, first of all, you only have 10 elements in 'myArray' but are initilizing 810 elements.

That's not exactly true ... The increment was i += 81, not ++i or something similar.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.