Smartypants
Smartypants

Reputation: 55

How to create an array of character arrays in c++? (only using iostream)

I am very new to c++.

Say I have this:

char arrOne[10];
char arrTwo[10];
char arrThree[10];

How can I create an array where each element in the array holds a character array like above?

The goal is to be able to call upon the index of the array of arrays to grab one of these character arrays when needed.

Keep in mind. I can ONLY use iostream.

Upvotes: 0

Views: 1150

Answers (2)

george kapoya
george kapoya

Reputation: 21

Hello I think you need to use a for/while loop to access each element in an array for example

char array[10] = "hello";

int i = 0;

while (i != '\0')
{
 if( array[i] = 'l')
 {
   array[i] = 'x';
 }
i++;
}
 cout <<"new array string" << array<<endl;

Upvotes: 0

muzio
muzio

Reputation: 310

You could create a char pointer array

char * array[3];

char arrOne[10]
char arrTwo[10]
char arrThree[10]

array[0] = arrOne;
array[1] = arrTwo;
array[2] = arrThree;

To access arrayOne ,for example, use array[0].

Upvotes: 2

Related Questions