filling 2-dimensional array
Brought to you by:
afanofosc,
afanofosc_99
Hi I would like to play melody from array of notes.
One note should be array[2] (pitch, duration).
Song will have 46 notes. I would like to fill it note by note;
But this does not work (compile error on first song[0] assignment):
int song[][];
int note[];
ArrayInit(note,0,2);
ArrayInit(song,note,46);
song[0] = {500, 100};
song[1] = {555, 100};
song[2] = {500, 100};
song[3] = {525, 100};
I can not find anything on Internet to make me understand how I can simply fill the song array. Everywhere is the same tutorial or guide.
It can be probably done by
song[0][0]=500; song[0][1]=100;
but this look awkward.
Is there better sollution?
The best way to do this is like this:
int song[][] = {{500, 100}, {555, 100}, {500, 100}, {525, 100}, ... };
where you would replace "..." with the rest of your pitch and duration arrays. You might consider making it an array of Tone structs. See
http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group___sound_module_functions_ga343ce8b1180f1083e6216f6d26dd1150.html
(google NXC PlayTones)
http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/ex_playtones_8nxc-example.html