Compiler gives “excess element in array initializer” warning in objective C with 2D C-array

General Tech Learning Aids/Tools 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I'm just learning Objective C and writing a program to aid people in learning to play the guitar. I wanted to create a 2D array containing (almost) all the notes on a guitar neck. Since there are six strings on the guitar and twelve notes in an octave, I created a 6 x 12 array. EDIT: solution is now at bottom

The intention here is for the array to be read as (string),(fret number).

int strings[6][12] = {
    { {0, 8},{0, 9},{0, 10},{0, 11} ,{0, 12} ,{0, 1}, {0, 2},{0, 3},{0, 4},{0, 5},{0, 6},{0, 7} },
    { {1, 3},{1, 4},{1, 5},{1, 6},{1, 7},{1, 8,},{1, 9},{1, 10},{1, 11} ,{1, 12},{1, 1},{1, 2} },
    { {2, 12},{2, 1},{2, 2},{2, 3},{2, 4},{2, 5},{2, 6},{2, 7},{2, 8},{2, 9},{2, 10},{2, 11} },
    { {3, 6}, {3, 7} , {3, 8} , {3, 9} ,{3, 10} ,{3, 11} ,{3, 12} ,{3, 1} ,{3, 2} ,{3, 3} ,{3, 4} ,{3, 5} },
    { 
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

Moved from the question to an actual answer post:

Thanks to you cool people, I figured out the problem. In the event someone else has this problem, here is my solution. I came to realize that the problem was that I had two integers assigned in each array slot, effectively making the array a 3D array. Since the first number in each pair is just the string number, I went ahead and just got rid of it. No more warnings!**

int strings[6][12] =    {8, 9, 10, 11, 12, 1 ,2 ,3, 4, 5, 6, 7, // High e
                        3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, // B
                        12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, //G
                        6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, // D
                        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, // A
                        8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7 }; // E

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community