excess elements in array initializer error in xcode

Dec 22, 2014 at 9:19pm
so im trying to simply spell out my friends name using arrays but i dont understand this error "excess elements in array initializer"

char sham[7][4] = {{'S', 'h', 'a', 'm', 'a', 'a', 's'},{'K', 'h', 'a', 'n'}};
Dec 22, 2014 at 9:21pm
in xcode, the second 'a' in the first name is underlined with red, in case that helps...?
Dec 22, 2014 at 9:32pm
Excess elements means that you have to many elements. When you create an array, you're telling the computer to set aside memory for x amount of bytes. Your char sham array is saying that you're going to have seven rows with four columns. The way I visualize this, at least 2d arrays, is like this {{,,,},{,,,},{,,,},{,,,},{,,,},{,,,},{,,,}}. Each curly bracket inside the main curly bracket represents a row and inside each of those curly brackets represent how many numbers or letters it can hold. In your case, you can only have four letters in each curly bracket for a total of seven rows.
Topic archived. No new replies allowed.