hi guys..! i need some help on how can i print out the output of my program.. the problem is, it will only print out the first char of a characters and i don't know how to use the pointer using an multidimensional array.
ex.
input:
jhonny
output:
j
here's my code:

char name[5][50];
*p;
for(i=0;i<5;i++)
 {
  cin.getline(name[i], 50)
 }
for(i=0;i<5;i++)
 {
 cout<<"*name[i]<<"\n";
  }

..i am using a string here..
guys i need your help for this..
i will appreciate your help so much.

thanks..

There a a bunch of different solutions. One being

char name[5][50];

	for(int i=0; i<5; i++)
	{
		char buffer[50];
		cin.getline(buffer, 49);
		buffer[strlen(buffer)] = '\0';
		strcpy(name[i], buffer);
	}

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

but you should look in to using std::string instead

but how can i use the pointer in here?

What are you wanting to use the pointer for? Just to get the output?

yes, it should use the pointer to display the output.

There is absolutely no point in using a pointer...

You almost got it right .

char name[5][50];
for(int i=0;i<5;i++)
 {
  cin.getline(name[i], 50);
 }
for(int i=0;i<5;i++)
 {
 //or cout<<name[i]<<"\n";
  cout<<**(name+i)<<endl;
  }
*name[i]

is equivalent to

**(name+i)

which displays only the first character of the line entered.
Also you don't require a buffer as

cin.getline(...)

automatically appends a '\0' .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.