Array of Arrays

how would i set up an array that contains a different array with in it. for example

1
2
3
4
5
6
char s[1000] = {
                  s[1]={1,2,3,4,5,6}
                  s[2]= {7,8,9,10,11,12}
                  s[3]= {stuff,stuff,stuff}

               };


would this be what it would look like? also if the user inputs a number would i be able to use that number to print the specific array. for example if the user inputs 2 i want it to print out 7,8,9,10,11,12.
You're describing multidimensional arrays, this is how you'd go about it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>

using namespace std;

int main()
{
	// 2 dimensional array, 4 rows by 5 columns
	int s[4][5] =
	{
			{1, 2, 3, 4, 17},
			{5, 6, 7, 8, 18},
			{9, 10, 11, 12, 19},
			{13, 14, 15, 16, 20}
	};

	// 2 dimensional array 3 rows by 3 columns compiler figures out number of rows based on initialisation
	int s2[][3] =
	{
			{9, 8, 6},
			{7, 9, 5},
			{4, 3, 2}
	};

	// Print row 2 (3rd row) of array s
	for (int i = 0; i < 5; ++i)
		cout << s[2][i] << " ";
	cout << endl << endl;

	// print column 0 (1st column) of s2
	for (int i = 0; i < 3; ++i)
		cout << s2[i][0] << endl;

}


also see the multidemnsional arrays section at http://www.cplusplus.com/doc/tutorial/arrays/
Topic archived. No new replies allowed.