too many initializers in character array

I've googled 'too many initializers' and the only problem people seem to have with this is where they have not made their array large enough to hold all the elements they need to use, for example value[2] = {'3','4','5'};

This does not appear to be my problem as I have increase my [50][50] to 500 and 5000 and the error still occurs.

I'm working on visual studio 2013.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int course;
	char table[50][50] = {
			{ "Course1, 2", "Thursday, 9am", "Friday, 10am" },
			{ "Course 3", "Monday, 10am", "Thursday, 10am" },
			{ "Course 4,5", "Monday, 11am", "Tuesday, 11am" },
			{ "Course 6,7", "Tuesday, 9am", "Wednesday, 2pm" },
			{ "Course 8", "Monday, 12am", "Thursday, 9am" },
			{ "Course 9", "Tuesday, 10am", "Wednesday, 11am" },
			{ "Course 10", "Friday, 9am", "Friday, 11am" "\n" } };
//rest of code going here
system("PAUSE");
return 0;
}
closed account (48T7M4Gy)
Remove all the intermediate brackets and it will compile. Your problem is char vs string and the way C - strings are stored. Most pof the 2500 character slots are empty/not used.
This "Course1, 2" is an 1-dimensional array of characters, hence
this { "Course1, 2", "Thursday, 9am", "Friday, 10am" } is already a 2-dimensional array

This:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int course;
	char table[50][50][50] = { // Note 3 dimensions
			{ "Course1, 2", "Thursday, 9am", "Friday, 10am" },
			{ "Course 3", "Monday, 10am", "Thursday, 10am" },
			{ "Course 4,5", "Monday, 11am", "Tuesday, 11am" },
			{ "Course 6,7", "Tuesday, 9am", "Wednesday, 2pm" },
			{ "Course 8", "Monday, 12am", "Thursday, 9am" },
			{ "Course 9", "Tuesday, 10am", "Wednesday, 11am" },
			{ "Course 10", "Friday, 9am", "Friday, 11am" "\n" } };
//rest of code going here
system("PAUSE");
return 0;
}
compiles
Thanks for the quick response! both solutions work.
Topic archived. No new replies allowed.