[Error] too many initializers for char array

Hey seniors,

I am facing a problem of initialization of character array, it gives error of too much initializer.

1
2
3
4
  int n=12;
	char *ptr;
	char array[n]= {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
	ptr=array;
I’m not a senior but I can see you’re trying to initialize a char [12] to a char[12][3]
Line 3 would work if you were creating a std::string array.

A 2D char array, as highwayman said, is what you are trying to create.
Topic archived. No new replies allowed.