passing array as parameters


hello running test code:


code: [select]
boolean requestaccepted = false;
uint8_t startcomunication[] = {0x81, 0x12, 0xf1, 0x81, 0x05};
uint8_t startcomunication_accepted[] = {0x80, 0xf1, 0x12, 0x03, 0xc1, 0xea, 0x8f, 0xc0};

void setup() {
  // put setup code here, run once:
  serial.begin(9600);
 
  if (sendrequest(startcomunication, startcomunication_accepted)) {
    serial.println("made");
  }

}

void loop() {
  // put main code here, run repeatedly:

}


boolean sendrequest(uint8_t tosend[], uint8_t toreceive) {
  (int = 0; < sizeof(tosend); i++) {
    serial.println(tosend[i], hex);
  }
  return true;
}


i pass array parameter function looks doesn't work? ide how it?

code: [select]
boolean sendrequest(uint8_t tosend[], uint8_t toreceive)
you @ least consistent in how write definitions of parameters function.

however, not main problem.  put square brackets on second parameter , try again.  it still won't work way want @ least output.

when passed functions arrays passed pointers hence use of sizeof() in function waste of time pointer size not array size.  incidentally, sizeof() not have worked anyway because returns number of bytes used array, not size of array.  you need pass size of array function actual array.


Arduino Forum > Using Arduino > Programming Questions > passing array as parameters


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor