1

I used to work on java i'm new to C. I'm facing some issues.

Here i'm continuosly receiving data from a source. After reaching the count 3 i need to passthe whole data from count 1 to 3 to another function.

void check_msg_id( uint8_t *recvdata) {
    uint8_t buffer1[3];
    cnt=0;
    buffer1[cnt]=recvdata;
    cnt++;

    if (cnt==3) {
        cnt=0;
    }

}

How can i pass the data from all counts to a buffer? Any help will be appreciated. Thanks in advance

Ravikiran
  • 45
  • 11
  • 1
    `buffer1[cnt]=recvdata;` If you didn't get errors/warnings from this line, please check that you have them enabled in your compiler. – user694733 Dec 17 '18 at 13:48
  • It looks like you wanted to do a loop but forgot to do so. You set `cnt` (of which we don't see any declaration) to `0`, then you increase it with `cnt++;` putting it to `1`, and then you have `if (cnt==3)` which is never going to be true. – Blaze Dec 17 '18 at 13:49
  • I think we need some more context to be able to help you :) Could you show us the function that calls check_msg_id() or whoe you are going to use char *tmp_recvdata? – Bregell Dec 17 '18 at 16:27

1 Answers1

1

You can pass the data to another function by.

void check_msg_id( uint8_t *recvdata) {
uint8_t buffer1[3];
cnt=0;
buffer1[cnt]=recvdata;
cnt++;

if (cnt==3) {
    cnt=0;
  pass_data(buffer1);  //create a function
}

}

You can pass this where ever you want.

yagami
  • 149
  • 2
  • 12