[Error] too many initializers for char array

Oct 14, 2019 at 6:55pm
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;
Oct 14, 2019 at 7:14pm
I’m not a senior but I can see you’re trying to initialize a char [12] to a char[12][3]
Oct 14, 2019 at 9:27pm
Oct 14, 2019 at 10:46pm
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.