0

Hi!
I'm new into C programming and Arduino.
I'm trying to display some data on several 7LED Digit Displays but I get this error and I don't know why.
This is my code:

int iasDigits[] = {0, 1, 2}; 

void sendToDisplay(unsigned int device, int digits, char value, unsigned int valueLength){
for(int i = 0; i < valueLength; i++){
  lc.setDigit(device, digits[i], value[i], false);
}
}

And this is how I call the function:

sendToDisplay(0, *iasDigits, intToChar(iasValue, IAS_LENGTH), IAS_LENGTH);

intToChar returns an array with all the integer digits in order to display them one by one.
iasDigits value sets the address where each value will be displayed.

So, when I'm trying to read the address from digits[i] array I get this error:

error: invalid types 'int[int]' for array subscript

error: invalid types 'char[int]' for array subscript

Same happens with value[i] array.

Edited by last1devil

2
Contributors
4
Replies
23
Views
3 Years
Discussion Span
Last Post by last1devil
0

In your function sendToDisplay, the object named digits is a single int.

So what are you trying to do here: digits[i] ? Digits is an int. Not an array. Likewise for value. value is a single char. Not an array.

Edited by Moschops

0

I'm trying to pass this array
int iasDigits[] = {0, 1, 2};
to sendtoDisplay function

1

Pass a pointer to the first member of the array.

void sendToDisplay(unsigned int device, int* digits, char* value, unsigned int valueLength){
for(int i = 0; i < valueLength; i++){
lc.setDigit(device, digits[i], value[i], false);
}

called like this

sendToDisplay(0, iasDigits, intToChar(iasValue, IAS_LENGTH), IAS_LENGTH);

If intToChar really does return a char array (or rather, something that decays to a char-pointer) it will work fine.

Edited by Moschops

Votes + Comments
Thank you!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.