typedef struct {
  uint8_t  pitch;

#define  MAX_NOTE  500

LearnNote  Noteseq[MAX_NOTE]; 

int learnindex=0;
void loop() {

void MyHandleNoteOn(byte channel, byte pitch, byte velocity){
  • You are misusing the title. You are not supposed to squeeze your question there. Instead you should give a brief description of your Problem. Beside that in your particular case you can only cast your array from LearnNote to uint8_t. You need to loop over all entries and copy them one-by-one into an int-array. – Kwasmich Apr 25 '17 at 11:34

Its not very clear what you are asking, but I think you are saying can you do this

uint8_t anArray[MAX_NOTE];
anArray = Noteseq.pitch;

In general the answer is no. However in this specific case off the top of my head I think you probably can (maybe). You have a struct which only contains bytes. The compiler will probably pack the sequentially so you will effectively have a contiguous sequence of bytes which you would be able to copy to the byte array by doing:

memcpy (anArray, Noteseq, MAX_NOTE);  // THIS IS BAD PRACTICE!

You can only do this in this case because the types are both 8bit numbers. Its not a good idea to do this copy between an array of structs and a POD type array is just asking for trouble.

Instead use a function to do it.

int* CopyPitch (LearnNote* source, int* destination, int count)
    for (int i = 0; i < count; ++i)
        destination[i] = source[i].pitch;

(You should really check for null pointers and stuff, but its just an example)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.